AddIpAddress

From: Ignacio (Ignacio_at_discussions.microsoft.com)
Date: 12/21/04


Date: Tue, 21 Dec 2004 05:53:03 -0800

Hi:

I try to use the api function AddIpAddress in VB.net, the definition is:

DWORD AddIPAddress(
IPAddr Address,
IPMask IpMask,
DWORD IfIndex,
PULONG NTEContext,
PULONG NTEInstance
);

I declare this function in VB.net

    Declare Function AddIPAddress Lib "Iphlpapi" (ByVal Address As UInt64,
ByRef IpMask As UInt64, ByRef IfIndex As Integer, ByVal NTEContext As IntPtr,
ByVal NTEInstance As IntPtr) As Integer
 
and because I need convert Ip sting to IPAddr, use the function inet_addr
with this definition:

unsigned long inet_addr(
  const char* cp
);

in VB.net
    Private Declare Function inet_addr Lib "WSOCK32.DLL" (ByVal cp As
IntPtr) As UInt64

when I call this function :

    Dim ip_str As String
    Dim mask_str As String
    Dim NTEContext As IntPtr
    Dim NTEInstance As IntPtr
    Dim iRetVal As Integer

    Dim ptr_ip As IntPtr = IntPtr.Zero
    Dim ptr_mask As IntPtr = IntPtr.Zero
    Dim IPAddress As UInt64
    Dim IPMask As UInt64

    ip_str = "192.168.0.100"
    ptr_ip = Marshal.StringToHGlobalAnsi(ip_str)
    IPAddress = inet_addr(ptr_ip)

    mask_str = "255.255.255.0"
    ptr_mask = Marshal.StringToHGlobalAnsi(mask_str)
    IPMask = inet_addr(ptr_mask)

    iRetVal = AddIPAddress(IPAddress, IPMask, 1, NTEContext, NTEInstance)
'in this case 1 is the Ifindex of the loopback interface

    iRetVal = AddIPAddress(IPAddress, IPMask, 16777219, NTEContext,
NTEInstance)
' in this case 16777219 is the IfIndex of the ethernet interface y get this
number with GetIfTable

when I use the AddIPAddress the return value is 87, INVALID_PARAMETER, in
both cases.

I dont known what is the error, Can you help me?

Thanks.



Relevant Pages

  • Help with Marshaling an Array of Pointers from COM to Managed Objects
    ... Dim pDesktop As IntPtr ... Dim pidlRecyclebin As IntPtr ... ByRef pceltFetched As IntPtr) As UInt32 ... 'Requests a pointer to an interface that allows a client to enumerate ...
    (microsoft.public.dotnet.framework.interop)
  • Re: A little C# -> VB.Net conversion help?
    ... > lpSecurityAttributes As IntPtr, ByVal dwCreationDisposition As ... > Dim hDevice As IntPtr ... > Dim hFile As IntPtr ... > pAlloc = Marshal.AllocHGlobal) ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: A little C# -> VB.Net conversion help?
    ... > lpSecurityAttributes As IntPtr, ByVal dwCreationDisposition As ... > Dim hDevice As IntPtr ... > Dim hFile As IntPtr ... > pAlloc = Marshal.AllocHGlobal) ...
    (microsoft.public.dotnet.languages.vb)
  • Re: A little C# -> VB.Net conversion help?
    ... > lpSecurityAttributes As IntPtr, ByVal dwCreationDisposition As ... > Dim hDevice As IntPtr ... > Dim hFile As IntPtr ... > pAlloc = Marshal.AllocHGlobal) ...
    (microsoft.public.dotnet.general)
  • SetPrinter for network printers
    ... Public dmDeviceName As String ... Public pSecurityDescriptor As IntPtr ... Dim pPrinterInfo As IntPtr ...
    (microsoft.public.dotnet.languages.vb)