----- Original Message ----- 
From: "Anssi Kolehmainen" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Sunday, May 02, 2004 12:42 PM
Subject: RE: [WinPcap-users] Capturing/Sending Packets In Visual Basic


> > Hey, I found out about your projects and WinPCap a little
> > while ago. So far,
> > I can see all of you have put forth a lot of effort into
> > making this. I had
> > a few questions though, since I'm not really a proficient C++
> > User. I do
> > have C++, and all the example files work, but I wanted to
> > know if it was
> > possible to use WPCap.dll or Packet.dll in Visual Basic using
> > API calls. I
> > have tried to convert some of the C++ API to VB, but it just
> > doesn't seem to
> > work. Here is an example:
> >
> > Private Declare Function PacketGetAdapterNames Lib
> > "packet.dll" (pStr As
> > String, BufferSize As Long) As Boolean
> >
> > I thought this would be a correct API call, but it seems to
> > have errors when
> > I call it. If anyone could help me on this issue, I would
> > greatly appriciate
> > it. Thanks!
>
> C function
> BOOLEAN PacketGetAdapterNames (PTSTR pStr, PULONG BufferSize)
>
> Would translate to
> Private Declare Function PacketGetAdapterNames lib "packet.dll"
>  (byval pStr as String, byref BufferSize as long) as long
>
> One big thing with VB is that it _doesn't_ support multi-threading. Multi
> threading happens if you use callback functions (like pcap_loop).

This is wrong: pcap_loop (and all the other APIs for receiving packets) do
not make use of any thread: they are simply blocking, and they execute your
callback whenever a packet is received from the kernel driver.

Regarding PacketGetAdapterNames, beware two important things:

1. I don't know the marshaling provided by VB, but pStr is NOT a single
string, it's a bunch of ANSI strings, terminated by a double NULL.
2. Remember that the Packet API is *discouraged*, as clearly written in the
documentation
(http://winpcap.polito.it/docs/docs31beta/html/group__packetapi.html), as it
is possible that it will change in the future release (and we did it in
WinPcap 3.1 beta). It's quite better to use the pcap API.

Have a nice day
GV

>
> Translating functions from C to VB is easy when you remember few simple
> things:
>  - ByVal = direct value
>  - ByRef = pointer to value (usually P or LP in front of C type)
>  - With strings byval = pointer to string, byref = pointer to pointer to
> string
>  - PTSTR = pointer to string = byval string
>  - PULONG = pointer to long = byref long
>  - BOOLEAN = long
>  - Nearly everything are longs
>  - C int = VB long
>  - C short = VB integer
>
>
> Following might work.
>
> Public Type PACKET
>  hEvent as long
>  Overlapped as long
>  Buffer as byte*1048576
>  Length as long
>  BytesReceived as long
>  bIoComplete as long
> End Type
>
> Private Declare Function PacketReceivePacket lib "packet.dll" (byref
Adapter
> as ADAPTER, byref Packet as PACKET, sync as long) as long
>
> But it might not work because you "need" to use PakcetAllocatePacket &
> PacketInitPacket... Maybe 'Dim lppacket as long' might work...
>
> In short: It can be done but it is a real pain because VB doesn't have
> pointers. (Like C/C++ has)
>
> Anssi Kolehmainen
>
>
>
> ==================================================================
>  This is the WinPcap users list. It is archived at
>  http://www.mail-archive.com/[EMAIL PROTECTED]/
>
>  To unsubscribe use
>  mailto: [EMAIL PROTECTED]
> ==================================================================
>





==================================================================
 This is the WinPcap users list. It is archived at
 http://www.mail-archive.com/[EMAIL PROTECTED]/

 To unsubscribe use 
 mailto: [EMAIL PROTECTED]
==================================================================

Reply via email to