Re: Problem calling C++ API
Ok, I've never worked with WRAPI (or VB.NET), but this might push you in some direction.
From searching the web the WRAPI_NDIS_DEVICE structure looks like this:
Code:
typedef struct
{
WCHAR* pDeviceName;
WCHAR* pDeviceDescription;
} WRAPI_NDIS_DEVICE;
So, wrapped in VB.NET, it should become something like this:
Code:
<StructLayout(LayoutKind.Sequential)> _
Public Structure WRAPI_NDIS_DEVICE
<MarshalAs(UnmanagedType.LPTStr)> Public pDeviceName As String
<MarshalAs(UnmanagedType.LPTStr)> Public pDeviceDescription As String
End Structure
Then, the import code (with a tiny modification):
Code:
<DllImport( _
"wrapi.dll", _
EntryPoint:="?WRAPIEnumerateDevices@@YAJPAPAUWRAPI_NDIS_DEVICE@@PAJ@Z", _
SetLastError:=True, CharSet:=CharSet.Unicode, ExactSpelling:=True, _
CallingConvention:=CallingConvention.Cdecl)> _
Public Function WRAPIEnumerateDevices(ByRef ppDeviceList As IntPtr, ByRef plItems As Int32) As Long
End Function
Then there is the code calling the function:
Code:
Dim pInfo As IntPtr = IntPtr.Zero
Dim iItems As Int32
Dim lRes As Long
Dim i As Int32
' call the method (add error checking)
lRes = WRAPIEnumerateDevices(pInfo, iItems)
Console.WriteLine("Number of devices :{0}", iItems)
' loop through all records
For i = 0 To iItems - 1
' marshal record
Dim pDevice As WRAPI_NDIS_DEVICE = _
CType(Marshal.PtrToStructure(pInfo, GetType(WRAPI_NDIS_DEVICE)), WRAPI_NDIS_DEVICE)
' use the record
Console.WriteLine("{0} - {1}", pDevice.pDeviceName, pDevice.pDeviceDescription)
' get next record
pInfo = New IntPtr(pInfo.ToInt32() + Marshal.SizeOf(pDevice))
Next
- petter
Re: Problem calling C++ API
Perfect, works like a charm :)
Thanks!