Signed-off-by: Chip Davis cdavis@codeweavers.com --- dlls/kernel32/powermgnt.c | 53 +++++++++++++++++++++++++++++++-------- include/winnt.h | 5 ++++ 2 files changed, 47 insertions(+), 11 deletions(-)
diff --git a/dlls/kernel32/powermgnt.c b/dlls/kernel32/powermgnt.c index 056dd9df692..190dc016c31 100644 --- a/dlls/kernel32/powermgnt.c +++ b/dlls/kernel32/powermgnt.c @@ -19,10 +19,15 @@
#include <stdarg.h>
+#define NONAMELESSUNION +#define NONAMELESSSTRUCT +#include "ntstatus.h" +#define WIN32_NO_STATUS #include "windef.h" #include "winbase.h" #include "winternl.h" #include "wine/debug.h" +#include "wine/heap.h"
WINE_DEFAULT_DEBUG_CHANNEL(powermgnt);
@@ -113,10 +118,36 @@ EXECUTION_STATE WINAPI SetThreadExecutionState(EXECUTION_STATE flags) */ HANDLE WINAPI PowerCreateRequest(REASON_CONTEXT *context) { - FIXME("(%p): stub\n", context); + COUNTED_REASON_CONTEXT nt_context; + HANDLE handle; + NTSTATUS status; + WCHAR module_name[MAX_PATH]; + + TRACE( "(%p)\n", context ); + + nt_context.Version = context->Version; + nt_context.Flags = context->Flags; + if (context->Flags & POWER_REQUEST_CONTEXT_SIMPLE_STRING) + RtlInitUnicodeString( &nt_context.u.SimpleString, context->Reason.SimpleReasonString ); + else if (context->Flags & POWER_REQUEST_CONTEXT_DETAILED_STRING) + { + int i; + + GetModuleFileNameW( context->Reason.Detailed.LocalizedReasonModule, module_name, ARRAY_SIZE(module_name) ); + RtlInitUnicodeString( &nt_context.u.s.ResourceFileName, module_name ); + nt_context.u.s.ResourceReasonId = context->Reason.Detailed.LocalizedReasonId; + nt_context.u.s.StringCount = context->Reason.Detailed.ReasonStringCount; + nt_context.u.s.ReasonStrings = heap_alloc( nt_context.u.s.StringCount * sizeof(UNICODE_STRING) ); + for (i = 0; i < nt_context.u.s.StringCount; i++) + RtlInitUnicodeString( &nt_context.u.s.ReasonStrings[i], context->Reason.Detailed.ReasonStrings[i] ); + }
- SetLastError(ERROR_CALL_NOT_IMPLEMENTED); - return INVALID_HANDLE_VALUE; + status = NtCreatePowerRequest( &handle, &nt_context ); + if (nt_context.Flags & POWER_REQUEST_CONTEXT_DETAILED_STRING) + heap_free( nt_context.u.s.ReasonStrings ); + if (status) + SetLastError( RtlNtStatusToDosError(status) ); + return status == STATUS_SUCCESS ? handle : INVALID_HANDLE_VALUE; }
/*********************************************************************** @@ -124,10 +155,10 @@ HANDLE WINAPI PowerCreateRequest(REASON_CONTEXT *context) */ BOOL WINAPI PowerSetRequest(HANDLE request, POWER_REQUEST_TYPE type) { - FIXME("(%p, %u): stub\n", request, type); - - SetLastError(ERROR_CALL_NOT_IMPLEMENTED); - return FALSE; + NTSTATUS status = NtSetPowerRequest( request, type ); + if (status) + SetLastError( RtlNtStatusToDosError(status) ); + return status == STATUS_SUCCESS; }
/*********************************************************************** @@ -135,8 +166,8 @@ BOOL WINAPI PowerSetRequest(HANDLE request, POWER_REQUEST_TYPE type) */ BOOL WINAPI PowerClearRequest(HANDLE request, POWER_REQUEST_TYPE type) { - FIXME("(%p, %u): stub\n", request, type); - - SetLastError(ERROR_CALL_NOT_IMPLEMENTED); - return FALSE; + NTSTATUS status = NtClearPowerRequest( request, type ); + if (status) + SetLastError( RtlNtStatusToDosError(status) ); + return status == STATUS_SUCCESS; } diff --git a/include/winnt.h b/include/winnt.h index 40d883e3a92..e73821112d3 100644 --- a/include/winnt.h +++ b/include/winnt.h @@ -5582,6 +5582,11 @@ typedef struct _SYSTEM_POWER_POLICY { } SYSTEM_POWER_POLICY, *PSYSTEM_POWER_POLICY;
+#define POWER_REQUEST_CONTEXT_VERSION 0 + +#define POWER_REQUEST_CONTEXT_SIMPLE_STRING 0x00000001 +#define POWER_REQUEST_CONTEXT_DETAILED_STRING 0x00000002 + typedef union _FILE_SEGMENT_ELEMENT { PVOID64 Buffer; ULONGLONG Alignment;