Sign in to follow this  
Followers 0
weaponx

[Resolved] DllStructGetData crashing AutoIt

2 posts in this topic

#1 ·  Posted (edited)

This should be the simplest thing. The first dllcall gets a count of device classes on your system. The second dllcall takes a pointer to a GUID array and populates it. The array is filling with pointers okay, but if you uncomment either of the noted lines below (they say "causes crash") it crashes hard.

#Include <WinAPI.au3>

;Retrieve count of device classes
$result = Dllcall("setupapi.dll","int", "SetupDiBuildClassInfoList", "dword", 0, "ptr",0, "dword", 0, "dword*", 0) ;Return class count
$Class_Count = $result[4]

;Create structure containing array of pointers to GUID structures
$aGUID = DllStructCreate("ptr[" & $Class_Count & "]")
$paGUID = DllStructGetPtr($aguid)

;Populate structure with GUID's of all device classes
$result = Dllcall("setupapi.dll","int", "SetupDiBuildClassInfoList", "dword", 0, "long_ptr",$paGUID, "dword", $Class_Count, "dword*", 0) ;Populate array with GUID's
If @ERROR Then 
    MsgBox(0,"","@ERROR: " & @ERROR & @CRLF & "@EXTENDED: " & @EXTENDED)
Else
    ;Check for WinAPI error
    $WinAPI_Error = _WinAPI_GetLastError()
    If $WinAPI_Error <> 0 Then
        ConsoleWrite("Error " & _WinAPI_GetLastError() & ": " & _WinAPI_GetLastErrorMessage()) ;Error 122: The data area passed to a system call is too small.
    Else
        Debug($result)
    EndIf
EndIf

;Loop through all GUID pointers
For $X = 1 to $Class_Count
    
    ;Retrieve pointer from structure
    $pGUID = DllStructGetData($aGUID,1,$X)
    
    ;Write pointer to console
    ConsoleWrite("["&$X&"]: " & $pGUID & @CRLF)
    
    ;Write GUID to console
    ;ConsoleWrite(_WinAPI_StringFromGUID($pGUID) & @CRLF) ;Causes crash
    
    ;Attempt to create new struct using pointer
    $GUID = DllStructCreate($tagGUID,$pGUID)
    If @ERROR Then MsgBox(0,"","@ERROR: " & @ERROR & @CRLF & "@EXTENDED: " & @EXTENDED)
    
    ;Attempt to retrieve first portion of GUID
    ;DllStructGetData($GUID,1) ;Causes crash
Next

;Dump array to console
Func Debug($aArray)
    For $X = 0 to Ubound($aArray)-1
        ConsoleWrite("["&$X&"]: " & $aArray[$X] & @CRLF)
    Next
    ConsoleWrite(@CRLF)
EndFunc
Edited by weaponx

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Eff it all. I fixed this trash. Only took 4 hours.

#Include <WinAPI.au3>

;Retrieve count of device classes
$result = Dllcall("setupapi.dll","int", "SetupDiBuildClassInfoList", "dword", 0, "ptr",0, "dword", 0, "dword*", 0) ;Return class count
$Class_Count = $result[4]

$tagGUID_ARRAY = ""
For $X = 1 to $Class_Count
    $tagGUID_ARRAY &= $tagGUID & ";"
Next

;Create structure containing array of pointers to GUID structures
$aGUID = DllStructCreate($tagGUID_ARRAY)
$paGUID = DllStructGetPtr($aguid)

;Populate structure with GUID's of all device classes
$result = Dllcall("setupapi.dll","int", "SetupDiBuildClassInfoList", "dword", 0, "ptr",$paGUID, "dword", $Class_Count, "dword*", 0) ;Populate array with GUID's
If @ERROR Then 
    MsgBox(0,"Dllcall","@ERROR: " & @ERROR & @CRLF & "@EXTENDED: " & @EXTENDED)
Else
    ;Check for WinAPI error
    $WinAPI_Error = _WinAPI_GetLastError()
    If $WinAPI_Error <> 0 Then
        ConsoleWrite("Error " & _WinAPI_GetLastError() & ": " & _WinAPI_GetLastErrorMessage())
        Exit
    Else
        Debug($result)
    EndIf
EndIf

$offset = 16 ;Number of bytes in GUID struct

For $X = 0 to $Class_Count-1
    $GUID = DllStructCreate($tagGUID,$paGUID + ($offset*$X))
    $pGUID = DllStructGetPtr($GUID)
    ConsoleWrite(_WinAPI_StringFromGUID($pGUID) & @CRLF)
Next 

;Dump array to console
Func Debug($aArray)
    For $X = 0 to Ubound($aArray)-1
        ConsoleWrite("["&$X&"]: " & $aArray[$X] & @CRLF)
    Next
    ConsoleWrite(@CRLF)
EndFunc

Device Class GUID Reference:

http://msdn.microsoft.com/en-us/library/ms791134.aspx

Edited by weaponx

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  
Followers 0