Jump to content
Sign in to follow this  
julmae

dllcall problem.

Recommended Posts

julmae

ok so heres my problem, dllcall in this func is crashing autoit, most likely due bad parametrs and i cant figure correct parameters out :/

Func PacketGetAdapterNames()
    Local $Dll
    Local $pStr
    Local $BufferSize
    Local $sAdapters
    
    $Dll = DllOpen("Packet.dll")
    If $Dll = -1 Then 
        Return -1
    EndIf
    
    $pStr = DllStructCreate("char")
    If @error <> 0 Then
        Return -2
    EndIf

    $BufferSize = DllStructGetSize($pStr)
    $sAdapters = DllCall($Dll, "str", "PacketGetAdapterNames", "ptr",  DllStructGetPtr($pStr), "long", $BufferSize)
    If @error <> 0 Then
        DllClose($Dll)
        Return 0
    Else
        Return $sAdapters
    EndIf
EndFunc

Info about PacketGetAdapterNames :

BOOLEAN PacketGetAdapterNames(PTSTR pStr, PULONG BufferSize)

Retrieve the list of available network adapters and their description.

Parameters:

pStr User allocated string that will be filled with the names of the adapters.

BufferSize Length of the buffer pointed by pStr.

Returns:

If the function succeeds, the return value is nonzero.

Usually, this is the first function that should be used to communicate with the driver. It returns the names of the adapters installed on the system and supported by WinPcap. After the names of the adapters, pStr contains a string that describes each of them.

all help would be welcome 8)

Share this post


Link to post
Share on other sites
GaryFrost

Why not just use wmi?

for example:

; Generated by AutoIt Scriptomatic

$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
$colItems = ""
$strComputer = "localhost"

$Output=""
$Output = $Output & "Computer: " & $strComputer  & @CRLF
$Output = $Output & "==========================================" & @CRLF
$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration", "WQL", _
                                          $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

If IsObj($colItems) then
   For $objItem In $colItems
      $Output = $Output & "Caption: " & $objItem.Caption & @CRLF
      $strDefaultIPGateway = $objItem.DefaultIPGateway(0)
      $Output = $Output & "DefaultIPGateway: " & $strDefaultIPGateway & @CRLF
      $Output = $Output & "Description: " & $objItem.Description & @CRLF
      $Output = $Output & "DNSDomain: " & $objItem.DNSDomain & @CRLF
      $Output = $Output & "DNSHostName: " & $objItem.DNSHostName & @CRLF
      $strIPAddress = $objItem.IPAddress(0)
      $Output = $Output & "IPAddress: " & $strIPAddress & @CRLF
      $Output = $Output & "IPEnabled: " & $objItem.IPEnabled & @CRLF
      $strIPSubnet = $objItem.IPSubnet(0)
      $Output = $Output & "IPSubnet: " & $strIPSubnet & @CRLF
      $Output = $Output & "MACAddress: " & $objItem.MACAddress & @CRLF
      if Msgbox(1,"WMI Output",$Output) = 2 then ExitLoop
      $Output=""
   Next
Else
   Msgbox(0,"WMI Output","No WMI Objects Found for class: " & "Win32_NetworkAdapterConfiguration" )
Endif
oÝ÷ Øȧ¢¹¨v'âq«b¢{h~)mzº.¶Ø^¢w¬^¦åyÖ®¶­s`£²vVæW&FVB'WFôB67&FöÖF0 ¢b33c·v&VÔfÆu&WGW&äÖÖVFFVÇÒ¢b33c·v&VÔfÆtf÷'v&DöæÇÒ#¢b33c¶6öÄFV×2ÒgV÷C²gV÷C°¢b33c·7G$6ö×WFW"ÒgV÷C¶Æö6Æ÷7BgV÷C° ¢b33c´÷WGWCÒgV÷C²gV÷C°¢b33c´÷WGWBÒb33c´÷WGWBfײgV÷C´6ö×WFW#¢gV÷C²fײb33c·7G$6ö×WFW"fײ5$Ä`¢b33c´÷WGWBÒb33c´÷WGWBfײgV÷C³ÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÒgV÷C²fײ5$Ä`¢b33c¶ö&¥tÔ6W'f6RÒö&¤vWBgV÷C·væÖv×G3¢b3#²b3#²gV÷C²fײb33c·7G$6ö×WFW"fײgV÷C²b3#·&ö÷Bb3#´4Õc"gV÷C²¢b33c¶6öÄFV×2Òb33c¶ö&¥tÔ6W'f6RäWV5VW'gV÷Cµ4TÄT5B¢e$ôÒvã3%ôæWGv÷&´FFW$6öæfwW&FöâtU$RVæ&ÆVBb333³ÒgV÷C²ÂgV÷CµuÂgV÷C²Âð¢b33c·v&VÔfÆu&WGW&äÖÖVFFVDzb33c·v&VÔfÆtf÷'v&DöæÇ ¤b4ö&¢b33c¶6öÄFV×2FVà¢f÷"b33c¶ö&¤FVÒâb33c¶6öÄFV×0¢b33c´÷WGWBÒb33c´÷WGWBfײgV÷C´6Föã¢gV÷C²fײb33c¶ö&¤FVÒä6Föâfײ5$Ä`¢b33c·7G$FVfVÇDvFWvÒb33c¶ö&¤FVÒäFVfVÇDvFWv¢b33c´÷WGWBÒb33c´÷WGWBfײgV÷C´FVfVÇDvFWv¢gV÷C²fײb33c·7G$FVfVÇDvFWvfײ5$Ä`¢b33c´÷WGWBÒb33c´÷WGWBfײgV÷C´FW67&Föã¢gV÷C²fײb33c¶ö&¤FVÒäFW67&Föâfײ5$Ä`¢b33c´÷WGWBÒb33c´÷WGWBfײgV÷C´Då4FöÖã¢gV÷C²fײb33c¶ö&¤FVÒäDå4FöÖâfײ5$Ä`¢b33c´÷WGWBÒb33c´÷WGWBfײgV÷C´Då4÷7DæÖS¢gV÷C²fײb33c¶ö&¤FVÒäDå4÷7DæÖRfײ5$Ä`¢b33c·7G$FG&W72Òb33c¶ö&¤FVÒäFG&W72¢b33c´÷WGWBÒb33c´÷WGWBfײgV÷C´FG&W73¢gV÷C²fײb33c·7G$FG&W72fײ5$Ä`¢b33c´÷WGWBÒb33c´÷WGWBfײgV÷C´Væ&ÆVC¢gV÷C²fײb33c¶ö&¤FVÒäVæ&ÆVBfײ5$Ä`¢b33c·7G$7V&æWBÒb33c¶ö&¤FVÒä7V&æWB¢b33c´÷WGWBÒb33c´÷WGWBfײgV÷C´7V&æWC¢gV÷C²fײb33c·7G$7V&æWBfײ5$Ä`¢b33c´÷WGWBÒb33c´÷WGWBfײgV÷C´Ô4FG&W73¢gV÷C²fײb33c¶ö&¤FVÒäÔ4FG&W72fײ5$Ä`¢b×6v&÷ÂgV÷CµtÔ÷WGWBgV÷C²Âb33c´÷WGWBÒ"FVâWDÆö÷¢b33c´÷WGWCÒgV÷C²gV÷C°¢æW@¤VÇ6P¢×6v&÷ÂgV÷CµtÔ÷WGWBgV÷C²ÂgV÷C´æòtÔö&¦V7G2f÷VæBf÷"6Æ73¢gV÷C²fײgV÷Cµvã3%ôæWGv÷&´FFW$6öæfwW&FöâgV÷C²¤VæF`

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites
julmae

Why not just use wmi?

Thanks for idea, but i would still prefer doing it trough this dll.

$pStr = DllStructCreate("char")

Your allocating enough space for only a single character.

mmh its still crashing on me even when i have allocated enough space :/

Share this post


Link to post
Share on other sites
GaryFrost

without having the dll, can only make a guess, here's a couple you could try (my guess is the 2nd one should work for you):

Edit: noticed your return type was set to string, should be int, that might be what's crashing your call, not sure.

Func PacketGetAdapterNames()
    Local $Dll
    Local $pStr
    Local $sAdapters

    $Dll = DllOpen("Packet.dll")
    If $Dll = -1 Then
        Return -1
    EndIf

    $pStr = DllStructCreate("char[1024]")
    If @error <> 0 Then
        Return -2
    EndIf

    $sAdapters = DllCall($Dll, "int", "PacketGetAdapterNames", "ptr", DllStructGetPtr($pStr), "int", 1024)
    If @error <> 0 Then
        DllClose($Dll)
        Return 0
    Else
        DllClose($Dll)
        Return $sAdapters
    EndIf
EndFunc   ;==>PacketGetAdapterNames
oÝ÷ Ù«­¢+Ø)Õ¹A­ÑÑÁÑÉ9µÌ ¤(%1½°ÀÌØíÍÁÑÉÌ(($ÀÌØíÍÁÑÉÌô±±
±° ÅÕ½ÐíA­Ð¹±°ÅÕ½Ðì°ÅÕ½Ðí¥¹ÐÅÕ½Ðì°ÅÕ½ÐíA­ÑÑÁÑÉ9µÌÅÕ½Ðì°ÅÕ½ÐíÍÑÈÅÕ½Ðì°ÅÕ½ÐìÅÕ½Ðì°ÅÕ½Ðí¥¹ÐÅÕ½Ðì°ÄÀÈФ(%%ÉɽȱÐìÐìÀQ¡¸($%IÑÕɸÀ(%±Í($%IÑÕɸÀÌØíÍÁÑÉÌ(%¹%)¹Õ¹ìôôÐíA­ÑÑÁÑÉ9µÌ(
Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.