Quantcast
Channel: AutoIt v3 - General Help and Support
Viewing all articles
Browse latest Browse all 12506

dll - help getting string from returned dll structure (DHCP_GetSubnetInfo)

$
0
0
Hi,
This is my first post, although I've been using the forums as a fantastic source of inspiration and help for a couple of years. I'm trying to get the SubnetName and SubnetComments back from a dll call to dhcpsapi, but seem to just get pointers to returned strings, and can't work out how to get the actual strings themselves. The function returns a dll structure, which includes the strings inside. I've looked at some other posts which have just made me more confused. Can anyone help? The code takes a string with the dhcp server's ip address, and another string with the subnetID. This is the code I've cobbled together so far, modifying the DHCP.au3 from amel27 here. It also uses a couple of functions I found on the forums to translate the $subnet string to a binary value, and then to it's int value:

[ autoit ]         
Func _DHCP_GetSubnetInfo($sDHCP, $subnet) Local $tEnumSubnetsParms = DllStructCreate("ptr SubnetInfoPtr;DWORD Subnet") Local $infoArray[4]=[0, 0, 0, 0], $tSubnetInfoStr, $tAddress, $aRet, $temp, $tempArray, $tSubnetInfo Local $returnedString ; Translate the $subnet string to a string of 32 bits $tempArray = StringSplit($subnet, ".") For $i = 1 To UBound($tempArray) -1 $temp = $temp & _binary($tempArray[$i]) Next ; Now turn this into an int value to pass to the DHCP server $subnet = _BinToInt($temp) $aRet = DllCall("Dhcpsapi.dll", "int", "DhcpGetSubnetInfo", _ "wstr", $sDHCP, _ "int", $subnet, _ "ptr", DllStructGetPtr($tEnumSubnetsParms, "SubnetInfoPtr") ) If $aRet[0] Then Return 2; SetError(2, $aRet[0]) ; ERR: Any runtime errors   ; Debug _ArrayDisplay($aRet) If DllStructGetData($tEnumSubnetsParms,"SubnetInfoPtr")=0 Then Return 1; SetError(1, 0, $infoArray) ; ERR: Not Found $tSubnetInfoStr = DllStructCreate("ptr SubnetAddress;ptr SubnetMask;ptr SubnetName;ptr SubnetComment;ptr PrimaryHost;ptr SubnetState", DllStructGetData($tEnumSubnetsParms,"SubnetInfoPtr")) $tSubnetInfo = DllStructCreate("char[" & DllStructGetData($tSubnetInfoStr, 3) & "]");  , DllStructGetData($tEnumSubnetsParms, "SubnetInfoPtr")) ; Debug If $tSubnetInfoStr = 0 Then MsgBox(0, "E", @error) EndIf ; Let's see what we have MsgBox(0, "G", DllStructGetData($tSubnetInfoStr, 1)) ; Freeing  memory DllCall("Dhcpsapi.dll", "none", "DhcpRpcFreeMemory", "ptr", DllStructGetData($tEnumSubnetsParms,"EnumInfoPtr")) Return $infoArray EndFunc

Thanks so much for any help anyone can give!

Viewing all articles
Browse latest Browse all 12506

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>