I have a wireless device that has a DLL that can be used to control
it. I'm trying to utilize VB.Net to control it, but several of the
functions in the DLL contain pointers which is proving to be quite the
challenge. The following DLL call keeps returning false and I can't
figure out why. I have tried changing the values that I pass to the
dll from ByRef to ByVal and vice versa as I have found that to work
with a few other DLL calls, but not this one. I'm hoping somone can
point me in the correct direction.
DLL being called:
BOOL AirpcapWrite ( PAirpcapHandle AdapterHandle, PCHAR
TxPacket, ULONG PacketLen )
Transmits a packet.
Parameters: AdapterHandle Handle to the adapter.
TxPacket Pointer to a buffer that contains the packet to be
transmitted.
PacketLen Length of the buffer pointed by the TxPacket argument, in
bytes.
Returns:TRUE on success.
where PAircapHandle is defined as typedef struct _AirpcapHandle *
PAirpcapHandle
The code that I am unable to get to work properly is as follows:
Imports System.Runtime.InteropServices
Public Class Form1
Structure AirpcapDeviceDescription
Dim address As IntPtr
Dim DeviceName As String
Dim DeviceDesciption As String
End Structure
Private Declare Function AirpcapWrite Lib "airpcap.dll" (ByVal
AdapterHandle As IntPtr, ByRef TxPacket As String, ByRef PacketLen As
Long) As Boolean
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim handle As IntPtr
Dim channel As Long
Dim TxPacket As IntPtr
Dim packetData As String
Dim packetLen As Long
packetData = "FFFFFFFF"
packetLen = Len(packetData)
TxPacket = Marshal.StringToHGlobalAuto(packetData)
'transmit a packet
If AirpcapWrite(handle, packetData, packetLen) = True
Then
Debug.Print("succesfully transmitted a packet")
End If End Sub End Class
I functioning code where I have been able to obtain the handle.
Thanks for the help!