Jump to content

using DllCall() when you don't know memory size


Recommended Posts

I have created some code that uses iphlpapi.dll to collect network information and create an XML file. This replaces the need to parse IPCONFIG output and combines information only found in the registry. It seems pretty fast considering all of the information is is gathering: adapter settings, metrics, driver details, and network statistics.

(see below for updated version)

The problem is that the GetAdaptersInfo() function expects you to navigate a linked list through pointers instead of assuming it's a packed array of structures (which is the way I wrote it).

Unless someone can help me with this, the function will not work on all systems.

One way to make it fail is to have an adapter that has more than one IP address.

Maybe not too common, but I need a solution that works over 99% of the time.

Look at the first several lines of the __IPH_AdaptersCapture function and you will see what I mean.

I have included the C structure information in comments.

The key would be to somehow copy from the struct _IP_ADAPTER_INFO* Next pointer into a predefined structure and just pad the original return structure with dummy fields.

Would also appreciate someone helping me with the net_convertToTimestamp() function.

I would like to convert a time_t value to a readable date and time string.

Another cool extension would be to have this automatically update when an adapter change is detected.

A callback could be registered to handle that.

Actually, there's a lot more information that this DLL can get such as routing tables, open ports, etc.

Edited by Gordon J. Tyler
Link to comment
Share on other sites

The problem is that the GetAdaptersInfo() function expects you to navigate a linked list through pointers

How is that a problem when DllStructCreate has an optional param called "pointer"?

Instead of making multiple topics for the same question, search the forum for "iphlpapi.dll" and you'll find at least one example.

Edited by Siao

"be smart, drink your wine"

Link to comment
Share on other sites

How is that a problem when DllStructCreate has an optional param called "pointer"?

Instead of making multiple topics for the same question, search the forum for "iphlpapi.dll" and you'll find at least one example.

Thank you - you "pointed" me in the right direction. :D

That param is exactly what I needed.

I am uploading the new and improved code.

IPHlpAPI.au3

If somebody out there decides to add to this, please upload your code.

I'm thinking someone out there might need routing tables or something...

Link to comment
Share on other sites

And here is the function that will convert a time_t value to a format more useful in AutoIt:

Func net_convertToTimestamp($val)
;; converts a time_t number to a date and time in the current timezone
  Local Const $reg_tz_info = "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\TimeZoneInformation"
  Local $offset = Number($val) - (Number(RegRead($reg_tz_info, "ActiveTimeBias")) * 60)
  Return _DateAdd('s', $offset, "1970/01/01 00:00:00")
EndFunc
Link to comment
Share on other sites

  • 2 months later...

I tried it and found an error line 109 must be:

Local $stAdapterInfo = DllStructCreate($IPAI & ";ubyte[" & String($nBufLen - DllStructGetSize($stIPAI))+1 & "]")

( There must be added one byte, or ERROR_BUFFER_OVERFLOW will occur muttley )

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

  • 9 months later...

A couple of people recently have been asking about a unique identifier. Using the script above you can change line 109 to:

Local $stAdapterInfo = DllStructCreate($IPAI & ";ubyte[" & String($nBufLen - DllStructGetSize($stIPAI) + 1) & "]")oÝ÷ Øv¯x¢w­«r¢ç(ºWn±æ§ÂÃ8Ëh¥ªìzØ^¢ëiº×ë¢b MDDjwkzÚâz÷­ã]­ë,¡ûayÊ&¦ë^­«­¢+Ù±½°ÀÌØí½=5½Õµ¹Ðô=©
ÉÑ ÅÕ½Ðí5Ma50ȹ=5½Õµ¹ÐÅÕ½Ðì¤(ÀÌØí½=5½Õµ¹Ð¹±½a50¡}%A!}
AQUI ¤¤(ÀÌØí½=5½Õµ¹Ð¹ÍÑAɽÁÉÑä ÅÕ½ÐíM±Ñ¥½¹1¹ÕÅÕ½Ðì°ÅÕ½ÐíaAÑ ÅÕ½Ðì¤ì)±½°ÀÌØí½5
9½ôÀÌØí½=5½Õµ¹Ð¹Í±ÑM¥¹±9½ ÅÕ½Ðì½9Q]=I-}%9

It might be a bit of overkill to retrieve all the other information as well but I didn't want to break up the excellent code from the original article.

WBD

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...