[DllImport("Wlanapi", EntryPoint = "WlanQueryInterface")]
public static extern uint WlanQueryInterface([In] IntPtr hClientHandle,
[In] ref Guid pInterfaceGuid,
WLAN_INTF_OPCODE OpCode,
IntPtr pReserved,
[Out] out uint pdwDataSize,
ref IntPtr ppData,
IntPtr pWlanOpcodeValueType);
<DllImport("Wlanapi", EntryPoint := "WlanQueryInterface")> _
Public Shared Function WlanQueryInterface(<[In]> ByVal hClientHandle As IntPtr, _
<[In]> ByRef pInterfaceGuid As Guid, ByVal OpCode As WLAN_INTF_OPCODE, _
ByVal pReserved As IntPtr, <Out> ByRef pdwDataSize As UInteger, _
ByRef ppData As IntPtr, ByVal pWlanOpcodeValueType As IntPtr) As UInteger
End Function
There is a managed WiFi API available on codeplex http://managedwifi.codeplex.com/
Depending on the opcode, the data returned in the memory pointed to by ppData can be:
WLAN_COUNTRY_OR_REGION_STRING_LIST
Please add some!
C#
IntPtr handle = IntPtr.Zero;
uint negotiatedVersion;
try
{
if (WlanOpenHandle(1, IntPtr.Zero, out negotiatedVersion, ref handle) != 0)
return;
IntPtr ptr = new IntPtr();
if (WlanEnumInterfaces(handle, IntPtr.Zero, ref ptr) != 0)
return;
WLAN_INTERFACE_INFO_LIST infoList = new WLAN_INTERFACE_INFO_LIST(ptr);
WlanFreeMemory(ptr);
Guid guid;
uint dataSize;
WLAN_CONNECTION_ATTRIBUTES connection;
// Call wlanqueryinterface for all the interfaces in the list
for (int i = 0; i < infoList.dwNumberOfItems; i++)
{
guid = infoList.InterfaceInfo[i].InterfaceGuid;
if (WlanQueryInterface(handle, ref guid, WLAN_INTF_OPCODE.wlan_intf_opcode_current_connection, IntPtr.Zero, out dataSize, ref ptr, IntPtr.Zero) != 0)
return;
connection = (WLAN_CONNECTION_ATTRIBUTES)Marshal.PtrToStructure(ptr, typeof(WLAN_CONNECTION_ATTRIBUTES));
// Do something here with the connection info....
WlanFreeMemory(ptr);
}
}
finally
{
if (handle != IntPtr.Zero)
WlanCloseHandle(handle, IntPtr.Zero);
}
VB.NET
Dim handle As IntPtr = IntPtr.Zero
Dim negotiatedVersion As UInteger
Try
If WlanOpenHandle(1, IntPtr.Zero, negotiatedVersion, handle) <> 0 Then
Return
End If
Dim ptr As New IntPtr()
If WlanEnumInterfaces(handle, IntPtr.Zero, ptr) <> 0 Then
Return
End If
Dim infoList As New WLAN_INTERFACE_INFO_LIST(ptr)
WlanFreeMemory(ptr)
Dim guid As Guid
Dim dataSize As UInteger
Dim connection As WLAN_CONNECTION_ATTRIBUTES
' Call wlanqueryinterface for all the interfaces in the list
For i As Integer = 0 To infoList.dwNumberOfItems - 1
guid = infoList.InterfaceInfo(i).InterfaceGuid
If WlanQueryInterface(handle, guid, WLAN_INTF_OPCODE.wlan_intf_opcode_current_connection, IntPtr.Zero, dataSize, ptr, _
IntPtr.Zero) <> 0 Then
Return
End If
connection = DirectCast(Marshal.PtrToStructure(ptr, GetType(WLAN_CONNECTION_ATTRIBUTES)), WLAN_CONNECTION_ATTRIBUTES)
' Do something here with the connection info....
WlanFreeMemory(ptr)
Next
Finally
If handle <> IntPtr.Zero Then
WlanCloseHandle(handle, IntPtr.Zero)
End If
End Try