I need to call the following api
DWORD GetAdaptersInfo(
PIP_ADAPTER_INFO pAdapterInfo,
PULONG pOutBufLen
);
What decalre ststement will be needed for these two pointers? 12 2914
Hi,
You may want to use WMI (System.Management namespace) to get network adapter
info.
If you still want to use the same API, this thread has an example (in C#) by
Willy Denoyette. Check it out: http://www.developersdex.com/csharp/...P11.phx.gbl%3E
HTH.
"Marni" <www> wrote in message news:#1**************@TK2MSFTNGP15.phx.gbl...
I need to call the following api
DWORD GetAdaptersInfo(
PIP_ADAPTER_INFO pAdapterInfo,
PULONG pOutBufLen
);
What decalre ststement will be needed for these two pointers?
If anyone can do a declare staement for me it will be very
helpfull.
"Shiva" <sh******@online.excite.com> wrote in message
news:O4****************@TK2MSFTNGP15.phx.gbl... Hi, You may want to use WMI (System.Management namespace) to get network
adapter info.
If you still want to use the same API, this thread has an example (in C#)
by Willy Denoyette. Check it out: http://www.developersdex.com/csharp/...P11.phx.gbl%3E HTH.
"Marni" <www> wrote in message
news:#1**************@TK2MSFTNGP15.phx.gbl... I need to call the following api DWORD GetAdaptersInfo( PIP_ADAPTER_INFO pAdapterInfo, PULONG pOutBufLen );
What decalre ststement will be needed for these two pointers?
Marni,
Just a sample of an API not yours,
I hope this helps?
Cor
\\\
Public Structure SYSTEMTIME
Public Year As Short
Public Month As Short
Public DayOfWeek As Short
Public Day As Short
Public Hour As Short
Public Minute As Short
Public Second As Short
Public Milliseconds As Short
End Structure
Public Declare Sub GetSystemTime _
Lib "kernel32" Alias "GetSystemTime" _
(ByRef lpSystemTime As SYSTEMTIME)
Public Declare Sub SetSystemTime _
Lib "kernel32" Alias "SetSystemTime" _
(ByRef lpSystemTime As SYSTEMTIME)
Private Sub Form1_Load(ByVal sender _
As System.Object, ByVal e As System.EventArgs) _
Handles MyBase.Load
Dim systime As SYSTEMTIME
GetSystemTime(systime)
MessageBox.Show(systime.Year.ToString())
MessageBox.Show(Now.ToString("MM/yyyy"))
End Sub
///
"Marni" <www> If anyone can do a declare staement for me it will be very helpfull. "Shiva" <sh******@online.excite.com> wrote in message news:O4****************@TK2MSFTNGP15.phx.gbl... Hi, You may want to use WMI (System.Management namespace) to get network adapter info.
If you still want to use the same API, this thread has an example (in C#) by Willy Denoyette. Check it out: http://www.developersdex.com/csharp/...P11.phx.gbl%3E HTH.
"Marni" <www> wrote in message
news:#1**************@TK2MSFTNGP15.phx.gbl... I need to call the following api DWORD GetAdaptersInfo( PIP_ADAPTER_INFO pAdapterInfo, PULONG pOutBufLen );
What decalre ststement will be needed for these two pointers?
Here is the VB.NET equivalent of Willy Denoyette's C# wrapper class for the
GetAdaptersInfo() API. The GetMacAddress() is the method that uses the API
(as appeared in his original post).
Hope this helps.
Public Class IpHelper
<DllImport("IphlpApi", CharSet:=CharSet.Ansi, SetLastError:=True),
System.Security.SuppressUnmanagedCodeSecurityAttri bute()> _
Public Shared Function GetAdaptersInfo(ByVal pAdapterInfo As IntPtr, ByRef
pOutBufLen As Integer) As Integer
End Function
Structure _IP_ADDR_STRING
Private [Next] As IntPtr
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=16)> _
Friend IpAddress As String
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=16)> _
Friend IpMask As String
Private Context As Integer
End Structure '_IP_ADDR_STRING
<StructLayout(LayoutKind.Sequential)> _
Structure _IP_ADAPTER_INFO
Friend [Next] As IntPtr
Private ComboIndex As Integer
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=260)> _
Friend AdapterName() As Byte
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=132)> _
Friend Description() As Byte
Friend AddressLength As Integer
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=8)> _
Friend Address() As Byte
Private Index As System.UInt32
Private Type As System.UInt32
Private DhcpEnabled As Integer
Private CurrentIpAddress As IntPtr
Friend IpAddressList As _IP_ADDR_STRING
Friend GatewayList As _IP_ADDR_STRING
Friend DhcpServer As _IP_ADDR_STRING
Private HaveWins As Boolean
Friend PrimaryWinsServer As _IP_ADDR_STRING
Friend SecondaryWinsServer As _IP_ADDR_STRING
Private LeaseObtained As Integer
Private LeaseExpires As Integer
End Structure
Public Function GetMacAddress() As ArrayList
Dim pAdapterInfo As IntPtr = IntPtr.Zero
Dim pOutBufLen As Integer = 0
Dim ad As New ArrayList
Dim ipinfo As New _IP_ADAPTER_INFO
Dim ret As Integer = GetAdaptersInfo(pAdapterInfo, pOutBufLen)
pAdapterInfo = Marshal.AllocHGlobal(pOutBufLen)
ret = GetAdaptersInfo(pAdapterInfo, pOutBufLen)
ipinfo = CType(Marshal.PtrToStructure(pAdapterInfo,
GetType(_IP_ADAPTER_INFO)), _IP_ADAPTER_INFO)
ad.Add(ipinfo.Address)
While Not ipinfo.Next.op_Equality(ipinfo.Next, IntPtr.Zero)
ipinfo = CType(Marshal.PtrToStructure(ipinfo.Next,
GetType(_IP_ADAPTER_INFO)), _IP_ADAPTER_INFO)
ad.Add(ipinfo.Address)
End While
Marshal.FreeHGlobal(pAdapterInfo)
Return ad
End Function 'GetMacAddress
End Class
"Marni" <www> wrote in message news:#l**************@tk2msftngp13.phx.gbl...
If anyone can do a declare staement for me it will be very
helpfull.
"Shiva" <sh******@online.excite.com> wrote in message
news:O4****************@TK2MSFTNGP15.phx.gbl... Hi, You may want to use WMI (System.Management namespace) to get network
adapter info.
If you still want to use the same API, this thread has an example (in C#)
by Willy Denoyette. Check it out: http://www.developersdex.com/csharp/...P11.phx.gbl%3E HTH.
"Marni" <www> wrote in message
news:#1**************@TK2MSFTNGP15.phx.gbl... I need to call the following api DWORD GetAdaptersInfo( PIP_ADAPTER_INFO pAdapterInfo, PULONG pOutBufLen );
What decalre ststement will be needed for these two pointers?
It must be the one I need. I looked at the sample suggested
by Shiva, but it's too complicated for me to do it in VB.
It looks simple, one api, 2 pointers, that's it. Or am I
just not realising the work involved?
BTW, if it's any easier, I do not need to access all the fields
of the first parameter, only the gateway ip field, that's it.
In case you need the WMI way of getting the gateway IP:
'Imports System.Management
Dim searcher As New ManagementObjectSearcher("SELECT DefaultIPGateway FROM
Win32_NetworkAdapterConfiguration")
Dim gw As ManagementObject
For Each gw In searcher.Get()
If Not (gw("DefaultIPGateway") Is Nothing) Then
Console.WriteLine(CType(gw("DefaultIPGateway"), String())(0))
End If
Next gw
HTH
"Marni" <www> wrote in message news:Of*************@TK2MSFTNGP11.phx.gbl...
It must be the one I need. I looked at the sample suggested
by Shiva, but it's too complicated for me to do it in VB.
It looks simple, one api, 2 pointers, that's it. Or am I
just not realising the work involved?
BTW, if it's any easier, I do not need to access all the fields
of the first parameter, only the gateway ip field, that's it.
"Shiva" <sh******@online.excite.com> wrote in message
news:eB*************@TK2MSFTNGP11.phx.gbl... In case you need the WMI way of getting the gateway IP:
'Imports System.Management
Dim searcher As New ManagementObjectSearcher("SELECT DefaultIPGateway FROM Win32_NetworkAdapterConfiguration") Dim gw As ManagementObject For Each gw In searcher.Get() If Not (gw("DefaultIPGateway") Is Nothing) Then Console.WriteLine(CType(gw("DefaultIPGateway"), String())(0)) End If Next gw
Do we get a gateway for each adapter? Is there a way to check which
adapter connects to the Internet. I.e. what do I do if I have an ethernet
card, a bluetooth usb device, and a wifi card, but only one of them is
connected to the internet, how can I know which one? HTH
"Marni" <www> wrote in message
news:Of*************@TK2MSFTNGP11.phx.gbl... It must be the one I need. I looked at the sample suggested by Shiva, but it's too complicated for me to do it in VB.
It looks simple, one api, 2 pointers, that's it. Or am I just not realising the work involved?
BTW, if it's any easier, I do not need to access all the fields of the first parameter, only the gateway ip field, that's it.
Thanks a lot
Just a few final points,
where can I find the documentation for command in html delimiters,
such as
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=16)>
These do not seem to come up on the 'Index' sensitive search.
Is there a list of all the possible commands in html delimiters?
Also, how do I print the result, for example, I wrote this test program:
Imports System.Text
Imports System.Runtime.InteropServices
Module Module1
Sub Main()
Dim a As ArrayList
Dim b As New IpHelper
a = b.GetMacAddress
Dim retval As String
Dim bytes(1000) As Byte
a.CopyTo(bytes)
retval = Encoding.ASCII.GetString(bytes)
MsgBox(retval)
' this did not work, sorry I simply don't know how to use ArrayList
End Sub
End Module
Public Class IpHelper
....
"Shiva" <sh******@online.excite.com> wrote in message
news:eG*************@TK2MSFTNGP10.phx.gbl... Here is the VB.NET equivalent of Willy Denoyette's C# wrapper class for
the GetAdaptersInfo() API. The GetMacAddress() is the method that uses the API (as appeared in his original post).
Hope this helps.
Public Class IpHelper <DllImport("IphlpApi", CharSet:=CharSet.Ansi, SetLastError:=True), System.Security.SuppressUnmanagedCodeSecurityAttri bute()> _
Public Shared Function GetAdaptersInfo(ByVal pAdapterInfo As IntPtr, ByRef pOutBufLen As Integer) As Integer
End Function
Structure _IP_ADDR_STRING
Private [Next] As IntPtr
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=16)> _
Friend IpAddress As String
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=16)> _
Friend IpMask As String
Private Context As Integer
End Structure '_IP_ADDR_STRING
<StructLayout(LayoutKind.Sequential)> _
Structure _IP_ADAPTER_INFO
Friend [Next] As IntPtr
Private ComboIndex As Integer
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=260)> _
Friend AdapterName() As Byte
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=132)> _
Friend Description() As Byte
Friend AddressLength As Integer
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=8)> _
Friend Address() As Byte
Private Index As System.UInt32
Private Type As System.UInt32
Private DhcpEnabled As Integer
Private CurrentIpAddress As IntPtr
Friend IpAddressList As _IP_ADDR_STRING
Friend GatewayList As _IP_ADDR_STRING
Friend DhcpServer As _IP_ADDR_STRING
Private HaveWins As Boolean
Friend PrimaryWinsServer As _IP_ADDR_STRING
Friend SecondaryWinsServer As _IP_ADDR_STRING
Private LeaseObtained As Integer
Private LeaseExpires As Integer
End Structure
Public Function GetMacAddress() As ArrayList
Dim pAdapterInfo As IntPtr = IntPtr.Zero
Dim pOutBufLen As Integer = 0
Dim ad As New ArrayList
Dim ipinfo As New _IP_ADAPTER_INFO
Dim ret As Integer = GetAdaptersInfo(pAdapterInfo, pOutBufLen)
pAdapterInfo = Marshal.AllocHGlobal(pOutBufLen)
ret = GetAdaptersInfo(pAdapterInfo, pOutBufLen)
ipinfo = CType(Marshal.PtrToStructure(pAdapterInfo, GetType(_IP_ADAPTER_INFO)), _IP_ADAPTER_INFO)
ad.Add(ipinfo.Address)
While Not ipinfo.Next.op_Equality(ipinfo.Next, IntPtr.Zero)
ipinfo = CType(Marshal.PtrToStructure(ipinfo.Next, GetType(_IP_ADAPTER_INFO)), _IP_ADAPTER_INFO)
ad.Add(ipinfo.Address)
End While
Marshal.FreeHGlobal(pAdapterInfo)
Return ad
End Function 'GetMacAddress
End Class "Marni" <www> wrote in message
news:#l**************@tk2msftngp13.phx.gbl... If anyone can do a declare staement for me it will be very helpfull. "Shiva" <sh******@online.excite.com> wrote in message news:O4****************@TK2MSFTNGP15.phx.gbl... Hi, You may want to use WMI (System.Management namespace) to get network adapter info.
If you still want to use the same API, this thread has an example (in
C#) by Willy Denoyette. Check it out: http://www.developersdex.com/csharp/...P11.phx.gbl%3E HTH.
"Marni" <www> wrote in message news:#1**************@TK2MSFTNGP15.phx.gbl... I need to call the following api DWORD GetAdaptersInfo( PIP_ADAPTER_INFO pAdapterInfo, PULONG pOutBufLen );
What decalre ststement will be needed for these two pointers?
Program doesn't work
!!!
"Shiva" <sh******@online.excite.com> wrote in message
news:eG*************@TK2MSFTNGP10.phx.gbl... Here is the VB.NET equivalent of Willy Denoyette's C# wrapper class for
the GetAdaptersInfo() API. The GetMacAddress() is the method that uses the API (as appeared in his original post).
Hope this helps.
Public Class IpHelper <DllImport("IphlpApi", CharSet:=CharSet.Ansi, SetLastError:=True), System.Security.SuppressUnmanagedCodeSecurityAttri bute()> _
Public Shared Function GetAdaptersInfo(ByVal pAdapterInfo As IntPtr, ByRef pOutBufLen As Integer) As Integer
End Function
Structure _IP_ADDR_STRING
Private [Next] As IntPtr
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=16)> _
Friend IpAddress As String
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=16)> _
Friend IpMask As String
Private Context As Integer
End Structure '_IP_ADDR_STRING
<StructLayout(LayoutKind.Sequential)> _
Structure _IP_ADAPTER_INFO
Friend [Next] As IntPtr
Private ComboIndex As Integer
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=260)> _
Friend AdapterName() As Byte
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=132)> _
Friend Description() As Byte
Friend AddressLength As Integer
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=8)> _
Friend Address() As Byte
Private Index As System.UInt32
Private Type As System.UInt32
Private DhcpEnabled As Integer
Private CurrentIpAddress As IntPtr
Friend IpAddressList As _IP_ADDR_STRING
Friend GatewayList As _IP_ADDR_STRING
Friend DhcpServer As _IP_ADDR_STRING
Private HaveWins As Boolean
Friend PrimaryWinsServer As _IP_ADDR_STRING
Friend SecondaryWinsServer As _IP_ADDR_STRING
Private LeaseObtained As Integer
Private LeaseExpires As Integer
End Structure
Public Function GetMacAddress() As ArrayList
Dim pAdapterInfo As IntPtr = IntPtr.Zero
Dim pOutBufLen As Integer = 0
Dim ad As New ArrayList
Dim ipinfo As New _IP_ADAPTER_INFO
Dim ret As Integer = GetAdaptersInfo(pAdapterInfo, pOutBufLen)
pAdapterInfo = Marshal.AllocHGlobal(pOutBufLen)
ret = GetAdaptersInfo(pAdapterInfo, pOutBufLen)
ipinfo = CType(Marshal.PtrToStructure(pAdapterInfo, GetType(_IP_ADAPTER_INFO)), _IP_ADAPTER_INFO)
ad.Add(ipinfo.Address)
While Not ipinfo.Next.op_Equality(ipinfo.Next, IntPtr.Zero)
ipinfo = CType(Marshal.PtrToStructure(ipinfo.Next, GetType(_IP_ADAPTER_INFO)), _IP_ADAPTER_INFO)
ad.Add(ipinfo.Address)
End While
Marshal.FreeHGlobal(pAdapterInfo)
Return ad
End Function 'GetMacAddress
End Class "Marni" <www> wrote in message
news:#l**************@tk2msftngp13.phx.gbl... If anyone can do a declare staement for me it will be very helpfull. "Shiva" <sh******@online.excite.com> wrote in message news:O4****************@TK2MSFTNGP15.phx.gbl... Hi, You may want to use WMI (System.Management namespace) to get network adapter info.
If you still want to use the same API, this thread has an example (in
C#) by Willy Denoyette. Check it out: http://www.developersdex.com/csharp/...P11.phx.gbl%3E HTH.
"Marni" <www> wrote in message news:#1**************@TK2MSFTNGP15.phx.gbl... I need to call the following api DWORD GetAdaptersInfo( PIP_ADAPTER_INFO pAdapterInfo, PULONG pOutBufLen );
What decalre ststement will be needed for these two pointers?
The program works, but only for GetMacAddress.
What do I do to obtain the gateway. I tried
ad.Add(ipinfo.GatewayList)
instead of
'ad.Add(ipinfo.Address)
and
Shared Sub main1()
Dim a As ArrayList
Dim b As New IpHelper
a = b.GetMacAddress
For Each c As _IP_ADDR_STRING In a
MsgBox(c.ToString)
Next
End Sub
strangely, the msgbox is printing the name of the structure
rather than an ip address, i.e
ConsoleApplication1.IpHelper+_IP_ADDR_STRING
Tia
"Marni" <www> wrote in message news:Ov**************@TK2MSFTNGP12.phx.gbl... Program doesn't work
!!!
"Shiva" <sh******@online.excite.com> wrote in message news:eG*************@TK2MSFTNGP10.phx.gbl... Here is the VB.NET equivalent of Willy Denoyette's C# wrapper class for the GetAdaptersInfo() API. The GetMacAddress() is the method that uses the
API (as appeared in his original post).
Hope this helps.
Public Class IpHelper <DllImport("IphlpApi", CharSet:=CharSet.Ansi, SetLastError:=True), System.Security.SuppressUnmanagedCodeSecurityAttri bute()> _
Public Shared Function GetAdaptersInfo(ByVal pAdapterInfo As IntPtr,
ByRef pOutBufLen As Integer) As Integer
End Function
Structure _IP_ADDR_STRING
Private [Next] As IntPtr
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=16)> _
Friend IpAddress As String
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=16)> _
Friend IpMask As String
Private Context As Integer
End Structure '_IP_ADDR_STRING
<StructLayout(LayoutKind.Sequential)> _
Structure _IP_ADAPTER_INFO
Friend [Next] As IntPtr
Private ComboIndex As Integer
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=260)> _
Friend AdapterName() As Byte
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=132)> _
Friend Description() As Byte
Friend AddressLength As Integer
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=8)> _
Friend Address() As Byte
Private Index As System.UInt32
Private Type As System.UInt32
Private DhcpEnabled As Integer
Private CurrentIpAddress As IntPtr
Friend IpAddressList As _IP_ADDR_STRING
Friend GatewayList As _IP_ADDR_STRING
Friend DhcpServer As _IP_ADDR_STRING
Private HaveWins As Boolean
Friend PrimaryWinsServer As _IP_ADDR_STRING
Friend SecondaryWinsServer As _IP_ADDR_STRING
Private LeaseObtained As Integer
Private LeaseExpires As Integer
End Structure
Public Function GetMacAddress() As ArrayList
Dim pAdapterInfo As IntPtr = IntPtr.Zero
Dim pOutBufLen As Integer = 0
Dim ad As New ArrayList
Dim ipinfo As New _IP_ADAPTER_INFO
Dim ret As Integer = GetAdaptersInfo(pAdapterInfo, pOutBufLen)
pAdapterInfo = Marshal.AllocHGlobal(pOutBufLen)
ret = GetAdaptersInfo(pAdapterInfo, pOutBufLen)
ipinfo = CType(Marshal.PtrToStructure(pAdapterInfo, GetType(_IP_ADAPTER_INFO)), _IP_ADAPTER_INFO)
ad.Add(ipinfo.Address)
While Not ipinfo.Next.op_Equality(ipinfo.Next, IntPtr.Zero)
ipinfo = CType(Marshal.PtrToStructure(ipinfo.Next, GetType(_IP_ADAPTER_INFO)), _IP_ADAPTER_INFO)
ad.Add(ipinfo.Address)
End While
Marshal.FreeHGlobal(pAdapterInfo)
Return ad
End Function 'GetMacAddress
End Class "Marni" <www> wrote in message news:#l**************@tk2msftngp13.phx.gbl... If anyone can do a declare staement for me it will be very helpfull. "Shiva" <sh******@online.excite.com> wrote in message news:O4****************@TK2MSFTNGP15.phx.gbl... Hi, You may want to use WMI (System.Management namespace) to get network adapter info.
If you still want to use the same API, this thread has an example (in C#) by Willy Denoyette. Check it out:
http://www.developersdex.com/csharp/...P11.phx.gbl%3E HTH.
"Marni" <www> wrote in message
news:#1**************@TK2MSFTNGP15.phx.gbl... I need to call the following api DWORD GetAdaptersInfo( PIP_ADAPTER_INFO pAdapterInfo, PULONG pOutBufLen );
What decalre ststement will be needed for these two pointers?
In the GetMacAddress() method, instead of ad.Add(ipinfo.Address), have
ad.Add(ipinfo.GatewayList.IpAddress).
It adds the gateway IP (as a string) to the array list. Individual elements
can be accessed from the array list as ad[0], ad[1]
HTH
"Marni" <www> wrote in message news:ON**************@TK2MSFTNGP11.phx.gbl...
The program works, but only for GetMacAddress.
What do I do to obtain the gateway. I tried
ad.Add(ipinfo.GatewayList)
instead of
'ad.Add(ipinfo.Address)
and
Shared Sub main1()
Dim a As ArrayList
Dim b As New IpHelper
a = b.GetMacAddress
For Each c As _IP_ADDR_STRING In a
MsgBox(c.ToString)
Next
End Sub
strangely, the msgbox is printing the name of the structure
rather than an ip address, i.e
ConsoleApplication1.IpHelper+_IP_ADDR_STRING
Tia
"Marni" <www> wrote in message news:Ov**************@TK2MSFTNGP12.phx.gbl... Program doesn't work
!!!
"Shiva" <sh******@online.excite.com> wrote in message news:eG*************@TK2MSFTNGP10.phx.gbl... Here is the VB.NET equivalent of Willy Denoyette's C# wrapper class for the GetAdaptersInfo() API. The GetMacAddress() is the method that uses the
API (as appeared in his original post).
Hope this helps.
Public Class IpHelper <DllImport("IphlpApi", CharSet:=CharSet.Ansi, SetLastError:=True), System.Security.SuppressUnmanagedCodeSecurityAttri bute()> _
Public Shared Function GetAdaptersInfo(ByVal pAdapterInfo As IntPtr,
ByRef pOutBufLen As Integer) As Integer
End Function
Structure _IP_ADDR_STRING
Private [Next] As IntPtr
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=16)> _
Friend IpAddress As String
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=16)> _
Friend IpMask As String
Private Context As Integer
End Structure '_IP_ADDR_STRING
<StructLayout(LayoutKind.Sequential)> _
Structure _IP_ADAPTER_INFO
Friend [Next] As IntPtr
Private ComboIndex As Integer
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=260)> _
Friend AdapterName() As Byte
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=132)> _
Friend Description() As Byte
Friend AddressLength As Integer
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=8)> _
Friend Address() As Byte
Private Index As System.UInt32
Private Type As System.UInt32
Private DhcpEnabled As Integer
Private CurrentIpAddress As IntPtr
Friend IpAddressList As _IP_ADDR_STRING
Friend GatewayList As _IP_ADDR_STRING
Friend DhcpServer As _IP_ADDR_STRING
Private HaveWins As Boolean
Friend PrimaryWinsServer As _IP_ADDR_STRING
Friend SecondaryWinsServer As _IP_ADDR_STRING
Private LeaseObtained As Integer
Private LeaseExpires As Integer
End Structure
Public Function GetMacAddress() As ArrayList
Dim pAdapterInfo As IntPtr = IntPtr.Zero
Dim pOutBufLen As Integer = 0
Dim ad As New ArrayList
Dim ipinfo As New _IP_ADAPTER_INFO
Dim ret As Integer = GetAdaptersInfo(pAdapterInfo, pOutBufLen)
pAdapterInfo = Marshal.AllocHGlobal(pOutBufLen)
ret = GetAdaptersInfo(pAdapterInfo, pOutBufLen)
ipinfo = CType(Marshal.PtrToStructure(pAdapterInfo, GetType(_IP_ADAPTER_INFO)), _IP_ADAPTER_INFO)
ad.Add(ipinfo.Address)
While Not ipinfo.Next.op_Equality(ipinfo.Next, IntPtr.Zero)
ipinfo = CType(Marshal.PtrToStructure(ipinfo.Next, GetType(_IP_ADAPTER_INFO)), _IP_ADAPTER_INFO)
ad.Add(ipinfo.Address)
End While
Marshal.FreeHGlobal(pAdapterInfo)
Return ad
End Function 'GetMacAddress
End Class "Marni" <www> wrote in message news:#l**************@tk2msftngp13.phx.gbl... If anyone can do a declare staement for me it will be very helpfull. "Shiva" <sh******@online.excite.com> wrote in message news:O4****************@TK2MSFTNGP15.phx.gbl... Hi, You may want to use WMI (System.Management namespace) to get network adapter info.
If you still want to use the same API, this thread has an example (in C#) by Willy Denoyette. Check it out:
http://www.developersdex.com/csharp/...P11.phx.gbl%3E HTH.
"Marni" <www> wrote in message
news:#1**************@TK2MSFTNGP15.phx.gbl... I need to call the following api DWORD GetAdaptersInfo( PIP_ADAPTER_INFO pAdapterInfo, PULONG pOutBufLen );
What decalre ststement will be needed for these two pointers?
Hi,
I am not quite sure about what you mean by 'html delimters'. To get help on
MarshalAs, look for MarshalAsAttribute class in the MSDN Help (just have the
Attribute suffix for any attribute name).
To access individual elements in an arraylist, use array-like indexing
syntax. Eg: retVal(0), retVal(1), etc
"Marni" <www> wrote in message news:#0**************@TK2MSFTNGP11.phx.gbl...
Thanks a lot
Just a few final points,
where can I find the documentation for command in html delimiters,
such as
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=16)>
These do not seem to come up on the 'Index' sensitive search.
Is there a list of all the possible commands in html delimiters?
Also, how do I print the result, for example, I wrote this test program:
Imports System.Text
Imports System.Runtime.InteropServices
Module Module1
Sub Main()
Dim a As ArrayList
Dim b As New IpHelper
a = b.GetMacAddress
Dim retval As String
Dim bytes(1000) As Byte
a.CopyTo(bytes)
retval = Encoding.ASCII.GetString(bytes)
MsgBox(retval)
' this did not work, sorry I simply don't know how to use ArrayList
End Sub
End Module
Public Class IpHelper
....
"Shiva" <sh******@online.excite.com> wrote in message
news:eG*************@TK2MSFTNGP10.phx.gbl... Here is the VB.NET equivalent of Willy Denoyette's C# wrapper class for
the GetAdaptersInfo() API. The GetMacAddress() is the method that uses the API (as appeared in his original post).
Hope this helps.
Public Class IpHelper <DllImport("IphlpApi", CharSet:=CharSet.Ansi, SetLastError:=True), System.Security.SuppressUnmanagedCodeSecurityAttri bute()> _
Public Shared Function GetAdaptersInfo(ByVal pAdapterInfo As IntPtr, ByRef pOutBufLen As Integer) As Integer
End Function
Structure _IP_ADDR_STRING
Private [Next] As IntPtr
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=16)> _
Friend IpAddress As String
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=16)> _
Friend IpMask As String
Private Context As Integer
End Structure '_IP_ADDR_STRING
<StructLayout(LayoutKind.Sequential)> _
Structure _IP_ADAPTER_INFO
Friend [Next] As IntPtr
Private ComboIndex As Integer
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=260)> _
Friend AdapterName() As Byte
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=132)> _
Friend Description() As Byte
Friend AddressLength As Integer
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=8)> _
Friend Address() As Byte
Private Index As System.UInt32
Private Type As System.UInt32
Private DhcpEnabled As Integer
Private CurrentIpAddress As IntPtr
Friend IpAddressList As _IP_ADDR_STRING
Friend GatewayList As _IP_ADDR_STRING
Friend DhcpServer As _IP_ADDR_STRING
Private HaveWins As Boolean
Friend PrimaryWinsServer As _IP_ADDR_STRING
Friend SecondaryWinsServer As _IP_ADDR_STRING
Private LeaseObtained As Integer
Private LeaseExpires As Integer
End Structure
Public Function GetMacAddress() As ArrayList
Dim pAdapterInfo As IntPtr = IntPtr.Zero
Dim pOutBufLen As Integer = 0
Dim ad As New ArrayList
Dim ipinfo As New _IP_ADAPTER_INFO
Dim ret As Integer = GetAdaptersInfo(pAdapterInfo, pOutBufLen)
pAdapterInfo = Marshal.AllocHGlobal(pOutBufLen)
ret = GetAdaptersInfo(pAdapterInfo, pOutBufLen)
ipinfo = CType(Marshal.PtrToStructure(pAdapterInfo, GetType(_IP_ADAPTER_INFO)), _IP_ADAPTER_INFO)
ad.Add(ipinfo.Address)
While Not ipinfo.Next.op_Equality(ipinfo.Next, IntPtr.Zero)
ipinfo = CType(Marshal.PtrToStructure(ipinfo.Next, GetType(_IP_ADAPTER_INFO)), _IP_ADAPTER_INFO)
ad.Add(ipinfo.Address)
End While
Marshal.FreeHGlobal(pAdapterInfo)
Return ad
End Function 'GetMacAddress
End Class "Marni" <www> wrote in message
news:#l**************@tk2msftngp13.phx.gbl... If anyone can do a declare staement for me it will be very helpfull. "Shiva" <sh******@online.excite.com> wrote in message news:O4****************@TK2MSFTNGP15.phx.gbl... Hi, You may want to use WMI (System.Management namespace) to get network adapter info.
If you still want to use the same API, this thread has an example (in
C#) by Willy Denoyette. Check it out: http://www.developersdex.com/csharp/...P11.phx.gbl%3E HTH.
"Marni" <www> wrote in message news:#1**************@TK2MSFTNGP15.phx.gbl... I need to call the following api DWORD GetAdaptersInfo( PIP_ADAPTER_INFO pAdapterInfo, PULONG pOutBufLen );
What decalre ststement will be needed for these two pointers?
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Fabian Müller |
last post by:
Hi all,
my question is as follows:
If have a class X and a class Y derived from X.
Constructor of X is X(param1, param2) .
Constructor of Y is Y(param1, ..., param4) .
|
by: hasho |
last post by:
Why is "call by address" faster than "call by value"?
|
by: Bern McCarty |
last post by:
I have run an experiment to try to learn some things about floating point
performance in managed C++. I am using Visual Studio
2003. I was hoping to get a feel for whether or not it would make...
|
by: John |
last post by:
Hi all,
This really is quite an urgent matter.
I have a page with multiple, dynamically-loaded user controls and when a
user clicks on a button, the whole form is submitted. Now at this stage...
|
by: Amaryllis |
last post by:
I'm trying to call a CL which is located on our AS400 from a Windows
application. I've tried to code it in different ways, but I seem to
get the same error every time. Does anyone have any clue...
| |
by: mitchellpal |
last post by:
i am really having a hard time trying to differentiate the
two..........i mean.....anyone got a better idea how each occurs?
|
by: shsingh |
last post by:
I have a class A containing some map as data variables. I creat an
object of class A on heap by allocatiing memory by using "malloc". This
will return me the required memory but the object is not...
|
by: cberthu |
last post by:
Hi all,
Is it possible to have two connects in the same rexx script to
different DB's?
I have to get data form on DB (with specifics selects and filter out
some values with RExx) and save the...
|
by: CryptiqueGuy |
last post by:
Consider the variadic function with the following prototype:
int foo(int num,...);
Here 'num' specifies the number of arguments, and assume that all the
arguments that should be passed to this...
|
by: Rahul |
last post by:
Hi Everyone,
I have the following code and i'm able to invoke the destructor
explicitly but not the constructor. and i get a compile time error
when i invoke the constructor, why is this so?
...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |