Jump to content
Sign in to follow this  
jaberwacky

[Resolved] DLLCall and Windows Functions

Recommended Posts

jaberwacky

This morning I began a foray into DLLCall and Windows functions. I began with "InitiateShutdown". I was able to get that to work after a little bit of fiddling. However this next function may be above my head -- "DevicePowerEnumDevices". I have no real use for it other than to practice DLLCall.

I can get it to return a populated array. The first value is zero, but the MSDN says that means that the function failed. What do you think? Why would it return a populated array?

Link to the page I'm using: (http://msdn.microsoft.com/en-us/library/aa373243%28v=VS.85%29.aspx).

Here is my code: (I'm sure this is all backwards and screwy)

Global Const $DEVICEPOWER_HARDWAREID = 0x80000000
Global Const $DEVICEPOWER_FILTER_DEVICES_PRESENT = 0x20000000
Global Const $DEVICEPOWER_AND_OPERATION = 0x40000000
Global Const $DEVICEPOWER_FILTER_WAKEENABLED = 0x08000000
Global Const $DEVICEPOWER_FILTER_ON_NAME = 0x02000000

Global Const $PDCAP_D0_SUPPORTED = 0x00000001
Global Const $PDCAP_D1_SUPPORTED = 0x00000002
Global Const $PDCAP_D2_SUPPORTED = 0x00000004
Global Const $PDCAP_D3_SUPPORTED = 0x00000008

Global Const $PDCAP_S0_SUPPORTED = 0x00010000
Global Const $PDCAP_S1_SUPPORTED = 0x00020000
Global Const $PDCAP_S2_SUPPORTED = 0x00040000
Global Const $PDCAP_S3_SUPPORTED = 0x00080000
Global Const $PDCAP_S4_SUPPORTED = 0x01000000
Global Const $PDCAP_S5_SUPPORTED = 0x02000000

Global Const $PDCAP_WAKE_FROM_D0_SUPPORTED = 0x00000010
Global Const $PDCAP_WAKE_FROM_D1_SUPPORTED = 0x00000020
Global Const $PDCAP_WAKE_FROM_D2_SUPPORTED = 0x00000040
Global Const $PDCAP_WAKE_FROM_D3_SUPPORTED = 0x00000080
Global Const $PDCAP_WAKE_FROM_S0_SUPPORTED = 0x00100000
Global Const $PDCAP_WAKE_FROM_S1_SUPPORTED = 0x00200000
Global Const $PDCAP_WAKE_FROM_S2_SUPPORTED = 0x00400000
Global Const $PDCAP_WAKE_FROM_S3_SUPPORTED = 0x00800000
Global Const $PDCAP_WARM_EJECT_SUPPORTED = 0x00000100

Global Const $queryFlags = BitOR($PDCAP_D0_SUPPORTED, $PDCAP_D1_SUPPORTED, $PDCAP_D2_SUPPORTED, $PDCAP_D3_SUPPORTED)

Global Const $MAX_PATH = 256

Global $uIndex = 0

Global $result

Global $PowrProf = DllOpen("PowrProf.dll")

If @error = -1 Then
    ConsoleWrite("DLL did not open." & @LF)
    Exit
EndIf

DllCall($PowrProf, "int", "DevicePowerOpen", "uint", 0)

Global $pBufferSize = DllStructCreate("uint buffer")

DllStructSetData($pBufferSize, "buffer", $MAX_PATH * 8)

Global $ptrDllStruct = DllStructGetPtr($pBufferSize)

Global $counter = 0

While 1
    $result = DllCall($PowrProf, _
            "int", "DevicePowerEnumDevices", _
            "uint", $uIndex, _
            "uint", $DEVICEPOWER_FILTER_DEVICES_PRESENT, _
            "uint", $queryFlags, _
            "wstr", 0, _
            "ptr", $ptrDllStruct)

    ConsoleWrite($result[4] & @LF)

    If $counter = $result[3] Then ExitLoop
    $uIndex += 1
    $counter += 1
WEnd

$result = DllCall($PowrProf, "int", "DevicePowerClose")

DllClose($PowrProf)
Edited by jaberwocky6669

Share this post


Link to post
Share on other sites
jaberwacky

I got it working!

here is what I changed:

Global $result = DllCall($PowrProf, _
        "int", "DevicePowerEnumDevices", _
        "uint", 0, _
        "uint", $DEVICEPOWER_FILTER_DEVICES_PRESENT, _
        "uint", $queryFlags, _
        "wstr", 0, _ ; changed this to "wstr"
        "ptr", $ptrDllStruct)

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  

×