Jump to content
Sign in to follow this  

psapi dllcall

Recommended Posts


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..

Share this post

Link to post
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
    GLobal $LPVOID_SIZE = 4

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

$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
    $GUI = GUICreate("",500,500)
    $Edit = GUICtrlCreateEdit($szDrivers,15,15,470,470)
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    MSgBox(16,"PSAPI.DLL","Error : Buffer too small for all drivers.")

Func GetDeviceDriverBaseName(Const $pDriver)
    $tDriverName = DllStructCreate("char[" & $MAX_DRIVER_NAME & "]")
    $Ret = DllCall("psapi.dll","int","GetDeviceDriverBaseName", _
                    "ptr",$pDriver, _
                    "ptr",DllStructGetPtr($tDriverName), _
    If @error OR NOT $Ret[0] Then
        Return SetError(1,0,"")
        Return DllStructGetData($tDriverName,1)

Share this post

Link to post
Share on other sites

yeah i know, i was more messing around how to get it 'translated' to autoit, but it is slowly becoming clear to me

Thanks :)

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...