Soft Declares Into Iphlpapi.dll - noob help.

I’ve not done a ton of declares into external libraries, and am unsure how to go about it with a specific function in the iphlpapi.dll windows library. Here is the function definition from the MSDN documentation:

DWORD GetIpNetTable( _Out_ PMIB_IPNETTABLE pIpNetTable, _Inout_ PULONG pdwSize, _In_ BOOL bOrder );

So, to soft declare this thing, I’ll want to do something like this:

soft declare Function GetIpNetTable Lib "Iphlpapi.dll" (something, somethingelse, anotherthing) as SomeDataType

As you may have noticed, the bit I’m struggling with is trying to figure out how to determine what to pass for the parameters and what sort of datatype to use for the return value. I suspect that a windows DWORD can just be thrown into a Xojo Integer, but I’m really pretty unsure.

In the Soft Declare documentation in the user guide, there is a somewhat helpful table that lists all the valid data types I can pass as parameters to a soft declare, but none seem to match up with what I want to do… i.e., what should I pass for a windows BOOL? UShort?

Can someone point me to how I decipher what types to use in my declares?


Somewhere that call will detail what an PMIB_IPNETTABLE is, a PULONG and BOOL

Actually clicking on the entries in the MSDN docs gets you that a PMIB_IPNetTable is a Ptr to one of

typedef struct _MIB_IPNETTABLE {
DWORD dwNumEntries;

a PULONG is likely a Ptr to a Ulong (uint32 maybe ?)

BOOL I’m not sure

But is you have the MSVC headers you should be able to locate them

And once you click on MIB_IPNETROW you find more structures

but you can define these as structures of the right size in Xojo & things should work

PULONG may be a byref UInt32.
BOOL either an integer or a boolean.
PMIB_IPNETTABLE a memoryblock of right size.

Looks like you can call twice. First with nil memoryblock to learn the size required and than call again with a new memoryblock.

soft declare Function GetIpNetTable Lib “Iphlpapi.dll” (pIpNetTable as Ptr, pdwSize as Integer, pOrder as Boolean) as Integer

Call it twice as Christian says. Once to get pdwSize. Then allocate a New MemoryBlock(pdwSize) and call it again to get the data.

Then you have to pick apart the Memoryblock to extract the info, but if you get that far, the debugger will help you visualize the contents.

It should go something like this:

[code] Soft Declare Function GetIpNetTable Lib “Iphlpapi.dll” (Table As Ptr, ByRef TableSize As Integer, Order As Boolean) As Integer

Dim size As Integer
Dim err As Integer = GetIpNetTable(Nil, size, False)

If err = 0 Then
Dim table As New MemoryBlock(size)
err = GetIpNetTable(table, size, False)
End If[/code]