Jump to content

psapi dllcall


Recommended Posts

Hi,

I'm new to autoit scripting, but i want to learn a bit more about dllcalls...

Made some calls work already, but now i'm stuck...so if someone knows how to do this please let me know..

below the syntax as it is on msdn..it's a psapi.dll call

BOOL WINAPI EnumDeviceDrivers(

__out LPVOID* lpImageBase,

__in DWORD cb,

__out LPDWORD lpcbNeeded

);

Can someone show me how to convert this to a autoit dllcall??

Thanks in advance..

Link to comment
Share on other sites

Working Example,enumerate all device drivers(by that i mean their files) from the system.Asking anything u need.

Tested in last RC.

#include <GUIConstantsEx.au3>

Global Const $MAX_DRIVERS = 1024
Global Const $MAX_DRIVER_NAME = 256

; Get Pointer size depending on the system's architeture
If @AutoItX64 Then
    Global $LPVOID_SIZE = 8
Else
    GLobal $LPVOID_SIZE = 4
EndIF

$tDriverArray = DllStructCreate("ptr[" & $MAX_DRIVERS & "]")
$tDriverNeeded = DllStructCreate("dword")
$Ret = DllCall("psapi.dll","int","EnumDeviceDrivers", _
        "ptr",DllStructGetPtr($tDriverArray), _
        "dword",DllStructGetSize($tDriverArray), _
        "ptr",DllStructGetPtr($tDriverNeeded))
If @error OR NOT $Ret[0] THen
    MsgBox(16,"PSAPI.DLL","Error calling EnumDeviceDrivers")
    Exit
EndIf

$iDriverCount = DllStructGetData($tDriverNeeded,1) / $LPVOID_SIZE
MsgBox(0,"Driver Count",$iDriverCount)

$szDrivers = ""
IF $iDriverCount <= $MAX_DRIVERS Then
    For $i=1 To $iDriverCount
        $szDrivers &= GetDeviceDriverBaseName(DllStructGetData($tDriverArray,1,$i)) & @CRLF
    Next
    
    $GUI = GUICreate("",500,500)
    $Edit = GUICtrlCreateEdit($szDrivers,15,15,470,470)
    
    GUISetState()
    
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
Else
    MSgBox(16,"PSAPI.DLL","Error : Buffer too small for all drivers.")
EndIf


Func GetDeviceDriverBaseName(Const $pDriver)
    $tDriverName = DllStructCreate("char[" & $MAX_DRIVER_NAME & "]")
    $Ret = DllCall("psapi.dll","int","GetDeviceDriverBaseName", _
                    "ptr",$pDriver, _
                    "ptr",DllStructGetPtr($tDriverName), _
                    "dword",DllStructGetSize($tDriverName))
    If @error OR NOT $Ret[0] Then
        Return SetError(1,0,"")
    Else
        Return DllStructGetData($tDriverName,1)
    EndIf
EndFUnc
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...