Type a page name and press Enter. You'll jump to the page if it exists, or you can create it if it doesn't.
To create a page in a module other than iphlpapi, prefix the name with the module name and a period.
GetAdaptersInfo (iphlpapi)
.
Private Const MAX_ADAPTER_NAME_LENGTH As Int32 = 256
Private Const MAX_ADAPTER_DESCRIPTION_LENGTH As Int32 = 128
Private Const MAX_ADAPTER_ADDRESS_LENGTH As Int32 = 8
<DllImport("iphlpapi.dll", EntryPoint:="GetAdaptersInfo", CharSet:=CharSet.Ansi)> _
Private Shared Function GetAdaptersInfo( _
ByVal pAdapterInfo As IntPtr, _
ByRef pBufOutLen As UInt64) As Int32
End Function
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Ansi)> _
Private Structure IP_ADAPTER_INFO
Dim [Next] As IntPtr
Dim ComboIndex As Int32
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=(MAX_ADAPTER_NAME_LENGTH + 4))> _
Dim AdapterName As String
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=(MAX_ADAPTER_DESCRIPTION_LENGTH + 4))> _
Dim Description As String
Dim AddressLength As UInt32
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=(MAX_ADAPTER_ADDRESS_LENGTH))> _
Dim Address() As Byte
Dim Index As Int32
Dim Type As UInt32
Dim DhcpEnabled As UInt32
Dim CurrentIpAddress As IP_ADDRESS_STRING
Dim IpAddressList As IP_ADDRESS_STRING
Dim GatewayList As IP_ADDRESS_STRING
Dim DhcpServer As IP_ADDRESS_STRING
Dim HaveWins As Boolean
Dim PrimaryWinsServer As IP_ADDRESS_STRING
Dim SecondaryWinsServer As IP_ADDRESS_STRING
Dim LeaseObtained As Int32
Dim LeaseExpires As Int32
End Structure
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Ansi)> _
Private Structure IP_ADDRESS_STRING
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=(4 * 4))> _
Dim value As String
End Structure
Sample Code:
Public Sub GetAdapters()
Dim structSize As Int32 = Marshal.SizeOf(GetType(IP_ADAPTER_INFO))
Dim pArray As IntPtr = Marshal.AllocHGlobal(structSize)
Dim len As UInt64 = Convert.ToUInt64(structSize)
Dim ret As Int32 = GetAdaptersInfo(pArray, len)
If ret = 111 Then
' Buffer was too small, reallocate the correct size for the buffer.
pArray = Marshal.ReAllocHGlobal(pArray, New IntPtr(Convert.ToInt64(len)))
ret = GetAdaptersInfo(pArray, len)
End If
If ret = 0 Then
' Call succeeded
Dim pEntry As IntPtr = pArray
Do
' Retrieve the adapter info from the memory address.
Dim Entry As IP_ADAPTER_INFO = CType(Marshal.PtrToStructure(pEntry, GetType(IP_ADAPTER_INFO)), IP_ADAPTER_INFO)
pEntry = Entry.Next
Loop Until IntPtr.op_Equality(pEntry, IntPtr.Zero)
End If
Marshal.FreeHGlobal(pArray)
End Sub
TODO - a short description
3/16/2007 7:31:57 AM - anfortas.geo@yahoo.com-216.204.61.86
Click to read this page4/6/2008 7:23:14 AM - anonymous
TODO - a short description
3/16/2007 8:17:31 AM - -63.69.129.2
Click to read this page4/6/2008 7:23:14 AM - anonymous
TODO - a short description
3/16/2007 8:17:31 AM - -63.69.129.2
Click to read this page4/6/2008 7:23:14 AM - anonymous
Please edit this page!
Do you have...
- helpful tips or sample code to share for using this API in managed code?
- corrections to the existing content?
- variations of the signature you want to share?
- additional languages you want to include?
Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).