You have wrong parameter.
DigiMarco wrote:
Code:
DllCall("RegisterPowerSettingNotification", "UInt", lidDetectorHwnd, "str", "5ca83367-6e45-459f-a27b-476b1d01c936", "UInt", 0)
RegisterPowerSettingNotification FunctionCode:
HPOWERNOTIFY WINAPI RegisterPowerSettingNotification(
__in HANDLE hRecipient,
__in LPCGUID PowerSettingGuid,
__in DWORD Flags
);
An LPCGUID is not a string. This is a pointer to a
GUID structure.
Code:
typedef struct _GUID {
DWORD Data1;
WORD Data2;
WORD Data3;
BYTE Data4[8];
} GUID;
Data1 Specifies the first 8 hexadecimal digits of the GUID.
Data2 Specifies the first group of 4 hexadecimal digits.
Data3 Specifies the second group of 4 hexadecimal digits.
Data4 Array of 8 bytes. The first 2 bytes contain the third group of 4 hexadecimal digits. The remaining 6 bytes contain the final 12 hexadecimal digits.
You can call
CLSIDFromString Function (COM)Code:
OnExit, ExitSub
Gui, +LastFound
hRecipient := WinExist()
String := "{5ca83367-6e45-459f-a27b-476b1d01c936}" ; LIDACTION
VarSetCapacity(PowerSettingGuid, 16, 0)
DllCall("ole32\CLSIDFromString", "UInt", &String, "UInt", &PowerSettingGuid)
hPowerNotify := DllCall("RegisterPowerSettingNotification", "UInt", hRecipient, "UInt", &PowerSettingGuid, "UInt", 0)
OnMessage(0x0218, "WM_POWERBROADCAST")
Return
ExitSub:
DllCall("UnregisterPowerSettingNotification", "UInt", hPowerNotify) ; Unregisters the power setting notification.
ExitApp
WM_POWERBROADCAST(wParam, lParam)
{
; Do what you want
Return, true ; An application should return TRUE if it processes this message.
}
or create structure step-by-step
Code:
OnExit, ExitSub
Gui, +LastFound
hRecipient := WinExist()
String := "5ca83367-6e45-459f-a27b-476b1d01c936" ; LIDACTION
VarSetCapacity(PowerSettingGuid, 16, 0)
NumPut("0x" . SubStr(String, 1, 8), PowerSettingGuid, 0, "UInt") ; DWORD Data1
NumPut("0x" . SubStr(String, 10, 4), PowerSettingGuid, 4, "UShort") ; WORD Data2
NumPut("0x" . SubStr(String, 15, 4), PowerSettingGuid, 6, "UShort") ; WORD Data3
NumPut("0x" . SubStr(String, 20, 2), PowerSettingGuid, 8, "UChar") ; BYTE Data4[1]
NumPut("0x" . SubStr(String, 22, 2), PowerSettingGuid, 9, "UChar") ; BYTE Data4[2]
NumPut("0x" . SubStr(String, 25, 2), PowerSettingGuid, 10, "UChar") ; BYTE Data4[3]
NumPut("0x" . SubStr(String, 27, 2), PowerSettingGuid, 11, "UChar") ; BYTE Data4[4]
NumPut("0x" . SubStr(String, 29, 2), PowerSettingGuid, 12, "UChar") ; BYTE Data4[5]
NumPut("0x" . SubStr(String, 31, 2), PowerSettingGuid, 13, "UChar") ; BYTE Data4[6]
NumPut("0x" . SubStr(String, 33, 2), PowerSettingGuid, 14, "UChar") ; BYTE Data4[7]
NumPut("0x" . SubStr(String, 35, 2), PowerSettingGuid, 15, "UChar") ; BYTE Data4[8]
hPowerNotify := DllCall("RegisterPowerSettingNotification", "UInt", hRecipient, "UInt", &PowerSettingGuid, "UInt", 0)
OnMessage(0x0218, "WM_POWERBROADCAST")
Return
ExitSub:
DllCall("UnregisterPowerSettingNotification", "UInt", hPowerNotify) ; Unregisters the power setting notification.
ExitApp
WM_POWERBROADCAST(wParam, lParam)
{
; Do what you want
Return, true ; An application should return TRUE if it processes this message.
}