(Win32) Create function pointer to PowerSetRequest

This commit is contained in:
Twinaphex 2015-10-11 10:57:12 +02:00
parent f4a5cbbe5b
commit 756b3de315

View File

@ -275,13 +275,16 @@ bool win32_suppress_screensaver(void *data, bool enable)
return false; return false;
#else #else
typedef HANDLE (WINAPI * PowerCreateRequestPtr)(REASON_CONTEXT *context); typedef HANDLE (WINAPI * PowerCreateRequestPtr)(REASON_CONTEXT *context);
typedef BOOL (WINAPI * PowerSetRequestPtr)(HANDLE PowerRequest, POWER_REQUEST_TYPE RequestType);
HMODULE kernel32 = GetModuleHandleW(L"kernel32.dll"); HMODULE kernel32 = GetModuleHandleW(L"kernel32.dll");
PowerCreateRequestPtr powerCreateRequest = PowerCreateRequestPtr powerCreateRequest =
(PowerCreateRequestPtr)GetProcAddress(kernel32, "PowerCreateRequest"); (PowerCreateRequestPtr)GetProcAddress(kernel32, "PowerCreateRequest");
PowerSetRequestPtr powerSetRequest =
(PowerSetRequestPtr)GetProcAddress(kernel32, "PowerSetRequest");
if(enable) if(enable)
{ {
if(powerCreateRequest) if(powerCreateRequest && powerSetRequest)
{ {
/* Windows 7, 8, 10 codepath */ /* Windows 7, 8, 10 codepath */
POWER_REQUEST_CONTEXT RequestContext; POWER_REQUEST_CONTEXT RequestContext;
@ -293,7 +296,7 @@ bool win32_suppress_screensaver(void *data, bool enable)
Request = PowerCreateRequest(&RequestContext); Request = PowerCreateRequest(&RequestContext);
PowerSetRequest( Request, PowerRequestDisplayRequired); powerSetRequest( Request, PowerRequestDisplayRequired);
return true; return true;
} }
else else