From: Robert Lippmann robert.lippmann.development@gmail.com
--- dlls/powrprof/powrprof.c | 49 ++++++++++++++++++++++++++++------------ 1 file changed, 34 insertions(+), 15 deletions(-)
diff --git a/dlls/powrprof/powrprof.c b/dlls/powrprof/powrprof.c index 7cfc6b20c13..c3078decc87 100644 --- a/dlls/powrprof/powrprof.c +++ b/dlls/powrprof/powrprof.c @@ -19,7 +19,6 @@
#include <stdarg.h> #include <stdlib.h> -#include "initguid.h" #include "ntstatus.h" #define WIN32_NO_STATUS #include "windef.h" @@ -51,19 +50,19 @@ static HANDLE PPRegSemaphore = NULL; /* Hacks to get and set power schemes These should really be stored in the registry */ typedef struct { - const GUID guid; - const WCHAR *name; + const GUID *const guid; + const WCHAR *const name; } power_scheme_info;
/* Static array for storing predefined power schemes */ static const power_scheme_info valid_power_schemes[] = { - {(const GUID) GUID_TYPICAL_POWER_SAVINGS, L"Balanced"}, - {(const GUID) GUID_MAX_POWER_SAVINGS, L"High Performance"}, - {(const GUID) GUID_MIN_POWER_SAVINGS, L"Power Saver"} + {&GUID_TYPICAL_POWER_SAVINGS, L"Balanced"}, + {&GUID_MAX_POWER_SAVINGS, L"Power Saver"}, + {&GUID_MIN_POWER_SAVINGS, L"High Performance"} }; /* Static variable for storing the active power scheme, set to Balanced by default */ -static GUID active_power_scheme = (const GUID) GUID_TYPICAL_POWER_SAVINGS; +static GUID const *active_power_scheme = &GUID_TYPICAL_POWER_SAVINGS;
NTSTATUS WINAPI CallNtPowerInformation( POWER_INFORMATION_LEVEL InformationLevel, @@ -303,24 +302,32 @@ BOOLEAN WINAPI WritePwrScheme(PUINT puiID, LPWSTR lpszName, LPWSTR lpszDescripti
DWORD WINAPI PowerGetActiveScheme(HKEY UserRootPowerKey, GUID **polguid) { + FIXME("should use registry\n"); + /* Windows throws an access violation if **polguid is NULL, + so I guess we will too. */ + TRACE("*polguid %p, active_power_scheme %s\n", wine_dbgstr_point(*polguid), + debugstr_guid(*active_power_scheme)); /* Windows SDK docs say use LocalFree to free this */ *polguid = LocalAlloc(LMEM_FIXED, sizeof(GUID)); if (*polguid == NULL) { return ERROR_NOT_ENOUGH_MEMORY; } - memcpy(*polguid, &active_power_scheme, sizeof(GUID)); + memcpy(*polguid, active_power_scheme, sizeof(GUID)); return ERROR_SUCCESS; }
DWORD WINAPI PowerSetActiveScheme(HKEY UserRootPowerKey, GUID *polguid) { size_t i; + + FIXME("should use registry\n"); + TRACE("polguid %s\n", debugstr_guid(*polguid)); for (i = 0; i < ARRAYSIZE(valid_power_schemes); i++) { - if (IsEqualGUID(polguid, &valid_power_schemes[i].guid)) + if (IsEqualGUID(polguid, valid_power_schemes[i].guid)) { - active_power_scheme = *polguid; + active_power_scheme = polguid; return ERROR_SUCCESS; } } @@ -339,16 +346,28 @@ DWORD WINAPI PowerReadFriendlyName(HKEY RootPowerKey, const GUID *Scheme, { size_t i; const WCHAR *name; - DWORD name_len; + DWORD name_len, result; + GUID current_guid;
+ FIXME("should use registry\n"); /* Check for invalid sub-group or power-setting GUIDs */ if (SubGroup != NULL || PowerSettings != NULL) { + FIXME("partial implementation\n"); return ERROR_CALL_NOT_IMPLEMENTED; } - for (i = 0; i < ARRAYSIZE(valid_power_schemes); i++) + for (i = 0; ; i++) { - if (IsEqualGUID(Scheme, &valid_power_schemes[i].guid)) + result = PowerEnumerate(NULL, NULL, NULL, ACCESS_SCHEME, i, (UCHAR *)¤t_guid, sizeof(GUID)); + if (result != ERROR_SUCCESS) + { + return result; + } + if (result == ERROR_NO_MORE_ITEMS) + { + break; + } + if (IsEqualGUID(Scheme, ¤t_guid)) { name = valid_power_schemes[i].name; name_len = (wcslen(name) + 1) * sizeof(WCHAR); @@ -357,7 +376,7 @@ DWORD WINAPI PowerReadFriendlyName(HKEY RootPowerKey, const GUID *Scheme, *BufferSize = name_len; return ERROR_MORE_DATA; } - wcscpy((WCHAR *)Buffer, name); + memcpy(Buffer, name, name_len); *BufferSize = name_len; return ERROR_SUCCESS; } @@ -396,7 +415,7 @@ DWORD WINAPI PowerEnumerate(HKEY key, const GUID *scheme, const GUID *subgroup, *buffer_size = sizeof(GUID); return ERROR_MORE_DATA; } - memcpy(buffer, &valid_power_schemes[index].guid, sizeof(GUID)); + memcpy(buffer, valid_power_schemes[index].guid, sizeof(GUID)); return ERROR_SUCCESS; }