These functions were split out in Windows Vista. This commit also updates the .spec with newer power related SDK calls.
From: Robert Lippmann robert.lippmann.development@gmail.com
These functions were split out in Windows Vista. This commit also updates the .spec with newer power related SDK calls. --- dlls/powrprof/Makefile.in | 4 +- dlls/powrprof/powersetting.c | 38 ++++++++ dlls/powrprof/powrprof.c | 12 --- dlls/powrprof/powrprof.spec | 168 ++++++++++++++++++++++++++++------- include/Makefile.in | 1 + include/powersetting.h | 35 ++++++++ 6 files changed, 213 insertions(+), 45 deletions(-) create mode 100644 dlls/powrprof/powersetting.c create mode 100644 include/powersetting.h
diff --git a/dlls/powrprof/Makefile.in b/dlls/powrprof/Makefile.in index d081c6af81e..3d606f88574 100644 --- a/dlls/powrprof/Makefile.in +++ b/dlls/powrprof/Makefile.in @@ -3,4 +3,6 @@ IMPORTLIB = powrprof IMPORTS = advapi32
SOURCES = \ - powrprof.c + powrprof.c \ + powersetting.c + diff --git a/dlls/powrprof/powersetting.c b/dlls/powrprof/powersetting.c new file mode 100644 index 00000000000..dd6c8e2f786 --- /dev/null +++ b/dlls/powrprof/powersetting.c @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2025 Robert Lippmann + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + + + +#include "powersetting.h" +#include "winerror.h" +#include "wine/debug.h" + +WINE_DEFAULT_DEBUG_CHANNEL(powrprof); + +DWORD WINAPI PowerGetActiveScheme(HKEY UserRootPowerKey, GUID **polguid) +{ + FIXME("(%p,%p) stub!\n", UserRootPowerKey, polguid); + return ERROR_CALL_NOT_IMPLEMENTED; +} + +DWORD WINAPI PowerSetActiveScheme(HKEY UserRootPowerKey, GUID *polguid) +{ + FIXME("(%p,%s) stub!\n", UserRootPowerKey, wine_dbgstr_guid(polguid)); + return ERROR_SUCCESS; +} + \ No newline at end of file diff --git a/dlls/powrprof/powrprof.c b/dlls/powrprof/powrprof.c index dcc7126b920..8df6aa50a7d 100644 --- a/dlls/powrprof/powrprof.c +++ b/dlls/powrprof/powrprof.c @@ -284,18 +284,6 @@ BOOLEAN WINAPI WritePwrScheme(PUINT puiID, LPWSTR lpszName, LPWSTR lpszDescripti return FALSE; }
-DWORD WINAPI PowerGetActiveScheme(HKEY UserRootPowerKey, GUID **polguid) -{ - FIXME("(%p,%p) stub!\n", UserRootPowerKey, polguid); - return ERROR_CALL_NOT_IMPLEMENTED; -} - -DWORD WINAPI PowerSetActiveScheme(HKEY UserRootPowerKey, GUID *polguid) -{ - FIXME("(%p,%s) stub!\n", UserRootPowerKey, wine_dbgstr_guid(polguid)); - return ERROR_SUCCESS; -} - DWORD WINAPI PowerReadDCValue(HKEY RootPowerKey, const GUID *Scheme, const GUID *SubGroup, const GUID *PowerSettings, PULONG Type, PUCHAR Buffer, DWORD *BufferSize) { FIXME("(%p,%s,%s,%s,%p,%p,%p) stub!\n", RootPowerKey, debugstr_guid(Scheme), debugstr_guid(SubGroup), debugstr_guid(PowerSettings), Type, Buffer, BufferSize); diff --git a/dlls/powrprof/powrprof.spec b/dlls/powrprof/powrprof.spec index 95d28178729..62b0fe53d34 100644 --- a/dlls/powrprof/powrprof.spec +++ b/dlls/powrprof/powrprof.spec @@ -1,32 +1,136 @@ -@ stdcall CallNtPowerInformation (long ptr long ptr long) -@ stdcall CanUserWritePwrScheme () -@ stdcall DeletePwrScheme (long) -@ stdcall EnumPwrSchemes (ptr long) -@ stdcall GetActivePwrScheme (ptr) -@ stdcall GetCurrentPowerPolicies (ptr ptr) -@ stdcall GetPwrCapabilities (ptr) -@ stdcall GetPwrDiskSpindownRange (ptr ptr) -@ stdcall IsAdminOverrideActive (ptr) -@ stdcall IsPwrHibernateAllowed () -@ stdcall IsPwrShutdownAllowed () -@ stdcall IsPwrSuspendAllowed () -@ stdcall PowerDeterminePlatformRole () -@ stdcall PowerDeterminePlatformRoleEx(long) -@ stdcall PowerEnumerate(long ptr ptr long long ptr ptr) -@ stdcall PowerGetActiveScheme (ptr ptr) -@ stdcall PowerSetActiveScheme (ptr ptr) -@ stdcall PowerReadDCValue (ptr ptr ptr ptr ptr ptr ptr) -@ stdcall PowerReadFriendlyName (ptr ptr ptr ptr ptr ptr) -@ stdcall PowerRegisterSuspendResumeNotification(long ptr ptr) -@ stdcall PowerUnregisterSuspendResumeNotification(ptr) -@ stdcall PowerSettingRegisterNotification(ptr long ptr ptr) -@ stdcall PowerSettingUnregisterNotification(ptr) -@ stdcall PowerWriteACValueIndex(ptr ptr ptr ptr long) -@ stdcall ReadGlobalPwrPolicy (ptr) -@ stdcall ReadProcessorPwrScheme (long ptr) -@ stdcall ReadPwrScheme (long ptr) -@ stdcall SetActivePwrScheme (long ptr ptr) -@ stdcall SetSuspendState (long long long) -@ stdcall WriteGlobalPwrPolicy (ptr) -@ stdcall WriteProcessorPwrScheme (long ptr) -@ stdcall WritePwrScheme (ptr str str ptr) +1 stdcall CallNtPowerInformation( ptr ptr long ptr long ) +2 stdcall CanUserWritePwrScheme() +3 stdcall DeletePwrScheme( long ) +4 stub DevicePowerClose +5 stub DevicePowerEnumDevices +6 stub DevicePowerOpen +7 stub DevicePowerSetDeviceState +8 stdcall EnumPwrSchemes( ptr ptr ) +9 stub GUIDFormatToGlobalPowerPolicy +10 stub GUIDFormatToPowerPolicy +11 stdcall GetActivePwrScheme( ptr ) +12 stdcall GetCurrentPowerPolicies( ptr ptr ) +13 stdcall GetPwrCapabilities( ptr ) +14 stdcall GetPwrDiskSpindownRange( ptr ptr ) +15 stdcall IsAdminOverrideActive( str ) +16 stdcall IsPwrHibernateAllowed() +17 stdcall IsPwrShutdownAllowed() +18 stdcall IsPwrSuspendAllowed() +19 stub LoadCurrentPwrScheme +20 stub MergeLegacyPwrScheme +21 stub PowerApplyPowerRequestOverride +22 stub PowerApplySettingChanges +23 stub PowerCanRestoreIndividualDefaultPowerScheme +24 stub PowerCleanupOverrides +25 stub PowerClearUserAwayPrediction +26 stub PowerCloseEnvironmentalMonitor +27 stub PowerCloseLimitsMitigation +28 stub PowerCloseLimitsPolicy +29 stub PowerCreatePossibleSetting +30 stub PowerCreateSetting +31 stub PowerDebugDifPowerPolicies +32 stub PowerDebugDifSystemPowerPolicies +33 stub PowerDebugDumpPowerPolicy +34 stub PowerDebugDumpPowerScheme +35 stub PowerDebugDumpSystemPowerCapabilities +36 stub PowerDebugDumpSystemPowerPolicy +37 stub PowerDeleteScheme +38 stdcall PowerDeterminePlatformRole() +39 stub PowerDeterminePlatformRoleEx +40 stub PowerDuplicateScheme +41 stdcall PowerEnumerate( ptr ptr ptr ptr long str ptr ) +42 stub PowerEnumerateSettings +43 stdcall PowerGetActiveScheme( ptr ptr ) +44 stub PowerGetActualOverlayScheme +45 stub PowerGetAdaptiveStandbyDiagnostics +46 stub PowerGetEffectiveOverlayScheme +47 stub PowerGetOverlaySchemes +48 stub PowerGetProfiles +49 stub PowerGetUserAwayMinPredictionConfidence +50 stub PowerGetUserConfiguredACPowerMode +51 stub PowerGetUserConfiguredDCPowerMode +52 stub PowerImportPowerScheme +53 stub PowerInformationWithPrivileges +54 stub PowerIsSettingRangeDefined +55 stub PowerOpenSystemPowerKey +56 stub PowerOpenUserPowerKey +57 stub PowerPolicyToGUIDFormat +58 stub PowerReadACDefaultIndex +59 stub PowerReadACValue +60 stub PowerReadACValueIndex +61 stub PowerReadACValueIndexEx +62 stub PowerReadDCDefaultIndex +63 stub PowerReadDCValue +64 stub PowerReadDCValueIndex +65 stub PowerReadDCValueIndexEx +66 stub PowerReadDescription +67 stub PowerReadFriendlyName +68 stub PowerReadIconResourceSpecifier +69 stub PowerReadPossibleDescription +70 stub PowerReadPossibleFriendlyName +71 stub PowerReadPossibleValue +72 stub PowerReadProfileAlias +73 stub PowerReadSecurityDescriptor +74 stub PowerReadSettingAttributes +75 stub PowerReadValueIncrement +76 stub PowerReadValueMax +77 stub PowerReadValueMin +78 stub PowerReadValueUnitsSpecifier +79 stub PowerReapplyActiveScheme +80 stub PowerRefreshProfileSettings +81 stub PowerRegisterEnvironmentalMonitor +82 stub PowerRegisterForEffectivePowerModeNotifications +83 stub PowerRegisterLimitsMitigation +84 stub PowerRegisterLimitsPolicy +85 stdcall PowerRegisterSuspendResumeNotification( long ptr ptr ) +87 stub PowerReplaceDefaultPowerSchemes +88 stub PowerReportLimitsEvent +89 stub PowerReportThermalEvent +90 stub PowerRestoreACDefaultIndex +91 stub PowerRestoreACProfileIndex +92 stub PowerRestoreDCDefaultIndex +93 stub PowerRestoreDCProfileIndex +94 stub PowerRestoreDefaultPowerSchemes +95 stub PowerRestoreIndividualDefaultPowerScheme +96 stub PowerSetActiveOverlayScheme +97 stdcall PowerSetActiveScheme( ptr ptr ) +98 stub PowerSetAlsBrightnessOffset +99 stub PowerSetBrightnessAndTransitionTimes +100 stub PowerSetUserAwayPrediction +101 stub PowerSetUserConfiguredACPowerMode +102 stub PowerSetUserConfiguredDCPowerMode +103 stub PowerSettingAccessCheck +104 stub PowerSettingAccessCheckEx +105 stdcall PowerSettingRegisterNotification( ptr long ptr ptr ) +107 stdcall PowerSettingUnregisterNotification( ptr ) +108 stub PowerUnregisterFromEffectivePowerModeNotifications +109 stdcall PowerUnregisterSuspendResumeNotification( ptr ) +111 stub PowerUpdateEnvironmentalMonitorThresholds +112 stub PowerUpdateLimitsMitigation +113 stub PowerWriteACDefaultIndex +114 stub PowerWriteACProfileIndex +115 stdcall PowerWriteACValueIndex( ptr ptr ptr ptr long ) +117 stub PowerWriteDCProfileIndex +118 stub PowerWriteDCValueIndex +119 stub PowerWriteDescription +120 stub PowerWriteFriendlyName +121 stub PowerWriteIconResourceSpecifier +122 stub PowerWritePossibleDescription +123 stub PowerWritePossibleFriendlyName +124 stub PowerWritePossibleValue +125 stub PowerWriteSecurityDescriptor +126 stub PowerWriteSettingAttributes +127 stub PowerWriteValueIncrement +128 stub PowerWriteValueMax +129 stub PowerWriteValueMin +130 stub PowerWriteValueUnitsSpecifier +131 stdcall ReadGlobalPwrPolicy( ptr ) +132 stdcall ReadProcessorPwrScheme( long ptr ) +133 stdcall ReadPwrScheme( long ptr ) +134 stdcall SetActivePwrScheme( long ptr ptr ) +135 stdcall SetSuspendState( long long long ) +136 stub ValidatePowerPolicies +137 stdcall WriteGlobalPwrPolicy( ptr ) +138 stdcall WriteProcessorPwrScheme( long ptr ) +139 stdcall WritePwrScheme( ptr wstr wstr ptr ) + diff --git a/include/Makefile.in b/include/Makefile.in index 2dd230423ef..37755dd05e4 100644 --- a/include/Makefile.in +++ b/include/Makefile.in @@ -640,6 +640,7 @@ SOURCES = \ physicalmonitorenumerationapi.h \ pktdef.h \ poppack.h \ + powersetting.h \ powrprof.h \ prntvpt.h \ processthreadsapi.h \ diff --git a/include/powersetting.h b/include/powersetting.h new file mode 100644 index 00000000000..97b3dbb4b43 --- /dev/null +++ b/include/powersetting.h @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2025 Robert Lippmann + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#ifndef _POWERSETTING_H +#define _POWERSETTING_H 1 + +#include <windef.h> + +#ifdef __cplusplus +extern "C" { +#endif + +DWORD WINAPI PowerGetActiveScheme(HKEY UserRootPowerKey, GUID **polguid); +DWORD WINAPI PowerSetActiveScheme(HKEY UserRootPowerKey, GUID *polguid); + +#ifdef __cplusplus +} +#endif + +#endif /* _POWERSETTING_H */
From: Robert Lippmann robert.lippmann.development@gmail.com
--- include/winnt.h | 11 +++++++++++ 1 file changed, 11 insertions(+)
diff --git a/include/winnt.h b/include/winnt.h index 722d2c3a542..6737c0f85ac 100644 --- a/include/winnt.h +++ b/include/winnt.h @@ -5799,6 +5799,17 @@ typedef enum _POWER_REQUEST_TYPE #define POWER_REQUEST_CONTEXT_SIMPLE_STRING 0x00000001 #define POWER_REQUEST_CONTEXT_DETAILED_STRING 0x00000002
+/* Define GUIDs for well known power schemes */ + +/* Power Saver Power Scheme {a1841308-3541-4fab-bc81-f71556f20b4a} */ +DEFINE_GUID( GUID_MAX_POWER_SAVINGS, 0xA1841308, 0x3541, 0x4FAB, 0xBC, 0x81, 0xF7, 0x15, 0x56, 0xF2, 0x0B, 0x4A ); + +/* High Performance Power Scheme {8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c} */ +DEFINE_GUID( GUID_MIN_POWER_SAVINGS, 0x8C5E7FDA, 0xE8BF, 0x4A96, 0x9A, 0x85, 0xA6, 0xE2, 0x3A, 0x8C, 0x63, 0x5C ); + +/* Balanced Power Scheme {381b4222-f694-41f0-9685-ff5bb260df2e} */ +DEFINE_GUID( GUID_TYPICAL_POWER_SAVINGS, 0x381B4222, 0xF694, 0x41F0, 0x96, 0x85, 0xFF, 0x5B, 0xB2, 0x60, 0xDF, 0x2E ); + typedef union _FILE_SEGMENT_ELEMENT { PVOID64 Buffer; ULONGLONG Alignment;
From: Robert Lippmann robert.lippmann.development@gmail.com
--- dlls/powrprof/Makefile.in | 2 +- dlls/powrprof/powersetting.c | 130 +++++++++++++++++++++++++++++++++-- 2 files changed, 125 insertions(+), 7 deletions(-)
diff --git a/dlls/powrprof/Makefile.in b/dlls/powrprof/Makefile.in index 3d606f88574..c165b76d54c 100644 --- a/dlls/powrprof/Makefile.in +++ b/dlls/powrprof/Makefile.in @@ -1,6 +1,6 @@ MODULE = powrprof.dll IMPORTLIB = powrprof -IMPORTS = advapi32 +IMPORTS = advapi32 kernelbase ole32
SOURCES = \ powrprof.c \ diff --git a/dlls/powrprof/powersetting.c b/dlls/powrprof/powersetting.c index dd6c8e2f786..2558c74f71b 100644 --- a/dlls/powrprof/powersetting.c +++ b/dlls/powrprof/powersetting.c @@ -16,23 +16,141 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */
- - +#include <string.h> +#include <stdarg.h> +#include <wchar.h> +#include <initguid.h> +#include "windows.h" +#include "objbase.h" #include "powersetting.h" -#include "winerror.h" #include "wine/debug.h"
WINE_DEFAULT_DEBUG_CHANNEL(powrprof);
+ +static const char active_power_scheme_key[] = + "SYSTEM\CurrentControlSet\Control\Power\User\PowerSchemes"; +static const char active_power_scheme_value[] = "ActivePowerScheme"; + +/* Windows stores these GUIDs in the registry without braces for some reason */ +static DWORD guid_to_registry(const GUID * const pguid, char *guid_str, int guid_str_size) +{ + int ret; + + ret = snprintf(guid_str, guid_str_size, + "%08lX-%04X-%04X-%04X-%012llX", + pguid->Data1, pguid->Data2, + pguid->Data3, + (pguid->Data4[0] << 8) | pguid->Data4[1], + ((ULONGLONG)pguid->Data4[2] << 40) | + ((ULONGLONG)pguid->Data4[3] << 32) | + ((ULONGLONG)pguid->Data4[4] << 24) | + ((ULONGLONG)pguid->Data4[5] << 16) | + ((ULONGLONG)pguid->Data4[6] << 8) | + (ULONGLONG)pguid->Data4[7]); + if(ret >= guid_str_size) + { + ERR("Buffer overflow, expected %u bytes, got %u\n", guid_str_size, ret); + SetLastError(ERROR_BUFFER_OVERFLOW); + return ERROR_BUFFER_OVERFLOW; + } + return ERROR_SUCCESS; +} +static DWORD get_or_create_active_power_scheme_key(HKEY *hkey) +{ + DWORD key_disposition, ret; + char default_scheme[39]; + + ret = RegCreateKeyExA(HKEY_LOCAL_MACHINE, active_power_scheme_key, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_READ | KEY_WRITE, NULL, hkey, &key_disposition); + if (ret != ERROR_SUCCESS) + { + return ret; + } + if (key_disposition != REG_CREATED_NEW_KEY) + { + return ERROR_SUCCESS; + } + /* Create the default power profile value */ + ret = guid_to_registry(&GUID_TYPICAL_POWER_SAVINGS, default_scheme, sizeof(default_scheme)); + if(ret != ERROR_SUCCESS) + { + return ret; + } + TRACE("Creating default power profile value %s\n", debugstr_a(active_power_scheme_value)); + return(RegSetValueExA(*hkey, active_power_scheme_value, 0, REG_SZ, (const BYTE *)default_scheme, strlen(default_scheme) + 1)); +} + DWORD WINAPI PowerGetActiveScheme(HKEY UserRootPowerKey, GUID **polguid) { - FIXME("(%p,%p) stub!\n", UserRootPowerKey, polguid); - return ERROR_CALL_NOT_IMPLEMENTED; + DWORD ret; + HKEY hkey; + char scheme_guid[39]; + WCHAR scheme_guid_w[39]; + DWORD scheme_guid_size = sizeof(scheme_guid); + + ret = get_or_create_active_power_scheme_key(&hkey); + if(ret != ERROR_SUCCESS) + { + return ret; + } + /* Windows SDK docs say this can be freed with LocalFree() */ + *polguid = LocalAlloc(LPTR, sizeof(GUID)); + if(*polguid == NULL) + { + return GetLastError(); + } + ret = RegQueryValueExA(hkey, active_power_scheme_value, NULL, NULL, (LPBYTE)scheme_guid, &scheme_guid_size); + if(ret != ERROR_SUCCESS) + { + return ret; + } + snprintf(scheme_guid, sizeof(scheme_guid),"{%s}", scheme_guid); + /* Windows SDK docs say this can be freed with LocalFree() */ + *polguid = LocalAlloc(LPTR, sizeof(GUID)); + if(*polguid == NULL) + { + return GetLastError(); + } + mbstowcs(scheme_guid_w, scheme_guid, sizeof(scheme_guid_w)); + ret = CLSIDFromString(scheme_guid_w, *polguid); + if(ret != S_OK) + { + return ERROR_INVALID_PARAMETER; + } + RegCloseKey(hkey); + return ERROR_SUCCESS; }
DWORD WINAPI PowerSetActiveScheme(HKEY UserRootPowerKey, GUID *polguid) { - FIXME("(%p,%s) stub!\n", UserRootPowerKey, wine_dbgstr_guid(polguid)); + DWORD ret; + HKEY hkey; + char scheme_guid[39]; + const DWORD guid_size = sizeof(scheme_guid); + + FIXME("Should use EnumeratePowerSettings to validate passed in GUID\n"); + if(!(IsEqualGUID(polguid, &GUID_MAX_POWER_SAVINGS)|| + IsEqualGUID(polguid, &GUID_MIN_POWER_SAVINGS)|| + IsEqualGUID(polguid, &GUID_TYPICAL_POWER_SAVINGS))) + { + return(ERROR_INVALID_PARAMETER); + } + ret = get_or_create_active_power_scheme_key(&hkey); + if(ret != ERROR_SUCCESS) + { + return ret; + } + ret = guid_to_registry(polguid, scheme_guid, guid_size); + if(ret != ERROR_SUCCESS) + { + return ret; + } + ret=RegSetValueExA(hkey, active_power_scheme_value, 0, REG_SZ, (const BYTE *)scheme_guid, strlen(scheme_guid) + 1); + if(ret != ERROR_SUCCESS) + { + return ret; + } + RegCloseKey(hkey); return ERROR_SUCCESS; }
\ No newline at end of file
From: Robert Lippmann robert.lippmann.development@gmail.com
--- configure | 1 + configure.ac | 1 + dlls/powrprof/tests/Makefile.in | 5 ++ dlls/powrprof/tests/powersetting.c | 107 +++++++++++++++++++++++++++++ 4 files changed, 114 insertions(+) create mode 100644 dlls/powrprof/tests/Makefile.in create mode 100644 dlls/powrprof/tests/powersetting.c
diff --git a/configure b/configure index ef7c99dd8e8..d249f566a4d 100755 --- a/configure +++ b/configure @@ -22718,6 +22718,7 @@ wine_fn_config_makefile dlls/pdh/tests enable_tests wine_fn_config_makefile dlls/photometadatahandler enable_photometadatahandler wine_fn_config_makefile dlls/pidgen enable_pidgen wine_fn_config_makefile dlls/powrprof enable_powrprof +wine_fn_config_makefile dlls/powrprof/tests enable_tests wine_fn_config_makefile dlls/printui enable_printui wine_fn_config_makefile dlls/prntvpt enable_prntvpt wine_fn_config_makefile dlls/prntvpt/tests enable_tests diff --git a/configure.ac b/configure.ac index 274591f5f53..fd552491c17 100644 --- a/configure.ac +++ b/configure.ac @@ -3011,6 +3011,7 @@ WINE_CONFIG_MAKEFILE(dlls/pdh/tests) WINE_CONFIG_MAKEFILE(dlls/photometadatahandler) WINE_CONFIG_MAKEFILE(dlls/pidgen) WINE_CONFIG_MAKEFILE(dlls/powrprof) +WINE_CONFIG_MAKEFILE(dlls/powrprof/tests) WINE_CONFIG_MAKEFILE(dlls/printui) WINE_CONFIG_MAKEFILE(dlls/prntvpt) WINE_CONFIG_MAKEFILE(dlls/prntvpt/tests) diff --git a/dlls/powrprof/tests/Makefile.in b/dlls/powrprof/tests/Makefile.in new file mode 100644 index 00000000000..e26fb91d878 --- /dev/null +++ b/dlls/powrprof/tests/Makefile.in @@ -0,0 +1,5 @@ +TESTDLL = powrprof.dll +IMPORTS = powrprof kernelbase ole32 advapi32 + +SOURCES = \ + powersetting.c diff --git a/dlls/powrprof/tests/powersetting.c b/dlls/powrprof/tests/powersetting.c new file mode 100644 index 00000000000..ce55239b226 --- /dev/null +++ b/dlls/powrprof/tests/powersetting.c @@ -0,0 +1,107 @@ +/* + * Tests for powersetting.c (powrprof.dll) + * + * Copyright 2025 Robert Lippmann + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#include "initguid.h" +#include "guiddef.h" +#include "windows.h" +#include "winreg.h" +#include "objbase.h" +#include "powersetting.h" + +#include "wine/test.h" + + START_TEST(powersetting) + { + GUID *initial_powerprof = NULL, *new_powerprof = NULL, *tmp_powerprof = NULL; + WCHAR guid_string[40], guid_string2[40]; + HKEY tmp_key[] = { HKEY_CLASSES_ROOT, HKEY_CURRENT_CONFIG, HKEY_CURRENT_USER, + HKEY_DYN_DATA, HKEY_LOCAL_MACHINE, HKEY_PERFORMANCE_DATA, + HKEY_PERFORMANCE_NLSTEXT, HKEY_USERS }; + DWORD ret; + register int i; + + /* save initial power scheme to restore when test is finished */ + ret = PowerGetActiveScheme(NULL, &initial_powerprof); + ok(ret == ERROR_SUCCESS, "Retrieval of inital power scheme failed: %lu\n", ret); + StringFromGUID2(initial_powerprof,guid_string, sizeof(guid_string)); + + /* Windows can have additional power schemes, wine currently cannot */ + if(winetest_platform_is_wine) + { + ok((IsEqualGUID(initial_powerprof,&GUID_MAX_POWER_SAVINGS) || + IsEqualGUID(initial_powerprof,&GUID_TYPICAL_POWER_SAVINGS) || + IsEqualGUID(initial_powerprof,&GUID_MIN_POWER_SAVINGS)), + "Initial powerscheme GUID is invalid: %ls\n", guid_string); + } + /* not testing setting 2nd parameter to NULL since that's an + access violation on windows */ + + /* Win32 docs say that the first parameter of PowerGetActiveScheme should be NULL, + but Windows appears to ignore it rather than throw an error. + So, we'll test with all the predefined HKEYs to allow for regression in case + this changes. + */ + for (i = 0; i < ARRAYSIZE(tmp_key); i++) + { + ret = PowerGetActiveScheme(tmp_key[i], &new_powerprof); + ok(ret == ERROR_SUCCESS, "GetActivePowerScheme failed with HKEY %p\n", + tmp_key[i]); + LocalFree(new_powerprof); + } + + /* Test PowerSetActiveScheme with null */ + ret = PowerSetActiveScheme(NULL,NULL); + ok(ret == ERROR_INVALID_PARAMETER, "PowerSetActiveScheme incorrectly return error code %lu\n", ret); + + /* Try to actually change the power profile */ + if (IsEqualGUID(initial_powerprof, &GUID_MIN_POWER_SAVINGS)) + { + new_powerprof = (GUID *) & GUID_MAX_POWER_SAVINGS; + } + else + { + new_powerprof = (GUID *) & GUID_MIN_POWER_SAVINGS; + } + StringFromGUID2(new_powerprof,guid_string,sizeof(guid_string)); + ret = PowerSetActiveScheme(NULL, new_powerprof); + ok(ret == ERROR_SUCCESS, "PowerSetActiveScheme failed setting to valid power scheme %ls: %lu\n", guid_string, ret); + + /* now try to retrieve it */ + ret = PowerGetActiveScheme(NULL, &tmp_powerprof); + ok(ret == ERROR_SUCCESS, "Could not retrieve power scheme after setting it to %ls, code %lu\n", guid_string, ret); + StringFromGUID2(tmp_powerprof, guid_string2, sizeof(guid_string2)); + ok(IsEqualGUID(tmp_powerprof, new_powerprof), "Retrieved incorrect power profile after set: expected %ls, got %ls\n", + guid_string,guid_string2); + LocalFree(tmp_powerprof); + + /* try to set with non-NULL first parameter */ + for (i = 0; i < ARRAYSIZE(tmp_key); i++) + { + ret = PowerSetActiveScheme(tmp_key[i], new_powerprof); + ok(ret == ERROR_SUCCESS, "PowerSetActiveScheme failed with HKEY %p\n", + tmp_key[i]); + } + /* restore original power scheme */ + ret = PowerSetActiveScheme(NULL, initial_powerprof); + ok(ret == ERROR_SUCCESS, "Could not reset power scheme back to initial state, code: %lu\n", ret); + LocalFree(initial_powerprof); + + } + \ No newline at end of file
From: Robert Lippmann robert.lippmann.development@gmail.com
--- dlls/powrprof/powersetting.c | 45 +++++++++++++++++++++++++++--- dlls/powrprof/tests/powersetting.c | 21 +++++++------- 2 files changed, 52 insertions(+), 14 deletions(-)
diff --git a/dlls/powrprof/powersetting.c b/dlls/powrprof/powersetting.c index 2558c74f71b..1ffe8c65e3c 100644 --- a/dlls/powrprof/powersetting.c +++ b/dlls/powrprof/powersetting.c @@ -54,6 +54,8 @@ static DWORD guid_to_registry(const GUID * const pguid, char *guid_str, int guid SetLastError(ERROR_BUFFER_OVERFLOW); return ERROR_BUFFER_OVERFLOW; } + CharLowerA(guid_str); + TRACE("GUID successfully converted to %s\n", debugstr_a(guid_str)); return ERROR_SUCCESS; } static DWORD get_or_create_active_power_scheme_key(HKEY *hkey) @@ -64,20 +66,29 @@ static DWORD get_or_create_active_power_scheme_key(HKEY *hkey) ret = RegCreateKeyExA(HKEY_LOCAL_MACHINE, active_power_scheme_key, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_READ | KEY_WRITE, NULL, hkey, &key_disposition); if (ret != ERROR_SUCCESS) { + ERR("RegCreateKeyExA failed: got error %ld\n", ret); return ret; } if (key_disposition != REG_CREATED_NEW_KEY) { + TRACE("Active power scheme key already exists\n"); return ERROR_SUCCESS; } /* Create the default power profile value */ ret = guid_to_registry(&GUID_TYPICAL_POWER_SAVINGS, default_scheme, sizeof(default_scheme)); if(ret != ERROR_SUCCESS) { + ERR("guid_to_registry failed: got error %ld\n", ret); return ret; } - TRACE("Creating default power profile value %s\n", debugstr_a(active_power_scheme_value)); - return(RegSetValueExA(*hkey, active_power_scheme_value, 0, REG_SZ, (const BYTE *)default_scheme, strlen(default_scheme) + 1)); + TRACE("Creating default power scheme value %s, and setting to %s\n", debugstr_a(active_power_scheme_value), + debugstr_a(default_scheme)); + ret = RegSetValueExA(*hkey, active_power_scheme_value, 0, REG_SZ, (const BYTE *)default_scheme, strlen(default_scheme) + 1); + if(ret != ERROR_SUCCESS) + { + ERR("RegSetValueExA for %s failed: got error %ld\n", debugstr_a(active_power_scheme_value), ret); + } + return ret; }
DWORD WINAPI PowerGetActiveScheme(HKEY UserRootPowerKey, GUID **polguid) @@ -88,6 +99,7 @@ DWORD WINAPI PowerGetActiveScheme(HKEY UserRootPowerKey, GUID **polguid) WCHAR scheme_guid_w[39]; DWORD scheme_guid_size = sizeof(scheme_guid);
+ TRACE("called\n"); ret = get_or_create_active_power_scheme_key(&hkey); if(ret != ERROR_SUCCESS) { @@ -102,19 +114,37 @@ DWORD WINAPI PowerGetActiveScheme(HKEY UserRootPowerKey, GUID **polguid) ret = RegQueryValueExA(hkey, active_power_scheme_value, NULL, NULL, (LPBYTE)scheme_guid, &scheme_guid_size); if(ret != ERROR_SUCCESS) { + ERR("RegQueryValueExA for %s failed: got error %ld\n", debugstr_a(active_power_scheme_value), ret); return ret; } - snprintf(scheme_guid, sizeof(scheme_guid),"{%s}", scheme_guid); + + TRACE("RegQueryValueExA for %s returned %s\n", debugstr_a(active_power_scheme_value), + debugstr_a(scheme_guid)); /* Windows SDK docs say this can be freed with LocalFree() */ *polguid = LocalAlloc(LPTR, sizeof(GUID)); if(*polguid == NULL) { return GetLastError(); } - mbstowcs(scheme_guid_w, scheme_guid, sizeof(scheme_guid_w)); + + ret = MultiByteToWideChar(CP_ACP, 0, scheme_guid, -1, scheme_guid_w + 1, scheme_guid_size); + if (ret == 0) + { + ERR("MultiByteToWideChar failed, got error %ld\n", GetLastError()); + LocalFree(*polguid); + return GetLastError(); + } + /* Add curly braces around string */ + scheme_guid_w[0] = L'{'; + scheme_guid_w[ret] = L'}'; + scheme_guid[ret + 1] = L'\0'; + TRACE("Converting GUID %s to CLSID\n", debugstr_w(scheme_guid_w)); ret = CLSIDFromString(scheme_guid_w, *polguid); if(ret != S_OK) { + ERR("Converting GUID %s to CLSID failed, got error %ld\n", + debugstr_a(scheme_guid), ret); + LocalFree(*polguid); return ERROR_INVALID_PARAMETER; } RegCloseKey(hkey); @@ -128,7 +158,12 @@ DWORD WINAPI PowerSetActiveScheme(HKEY UserRootPowerKey, GUID *polguid) char scheme_guid[39]; const DWORD guid_size = sizeof(scheme_guid);
+ TRACE("Called with %s\n", debugstr_guid(polguid)); FIXME("Should use EnumeratePowerSettings to validate passed in GUID\n"); + if(!polguid) + { + return(ERROR_INVALID_PARAMETER); + } if(!(IsEqualGUID(polguid, &GUID_MAX_POWER_SAVINGS)|| IsEqualGUID(polguid, &GUID_MIN_POWER_SAVINGS)|| IsEqualGUID(polguid, &GUID_TYPICAL_POWER_SAVINGS))) @@ -145,9 +180,11 @@ DWORD WINAPI PowerSetActiveScheme(HKEY UserRootPowerKey, GUID *polguid) { return ret; } + TRACE("Setting %s to %s\n", debugstr_a(active_power_scheme_value), debugstr_a(scheme_guid)); ret=RegSetValueExA(hkey, active_power_scheme_value, 0, REG_SZ, (const BYTE *)scheme_guid, strlen(scheme_guid) + 1); if(ret != ERROR_SUCCESS) { + ERR("RegSetValueExA for %s failed: got error %ld\n", debugstr_a(active_power_scheme_value), ret); return ret; } RegCloseKey(hkey); diff --git a/dlls/powrprof/tests/powersetting.c b/dlls/powrprof/tests/powersetting.c index ce55239b226..c3c1da6f292 100644 --- a/dlls/powrprof/tests/powersetting.c +++ b/dlls/powrprof/tests/powersetting.c @@ -30,7 +30,6 @@ START_TEST(powersetting) { GUID *initial_powerprof = NULL, *new_powerprof = NULL, *tmp_powerprof = NULL; - WCHAR guid_string[40], guid_string2[40]; HKEY tmp_key[] = { HKEY_CLASSES_ROOT, HKEY_CURRENT_CONFIG, HKEY_CURRENT_USER, HKEY_DYN_DATA, HKEY_LOCAL_MACHINE, HKEY_PERFORMANCE_DATA, HKEY_PERFORMANCE_NLSTEXT, HKEY_USERS }; @@ -40,7 +39,6 @@ /* save initial power scheme to restore when test is finished */ ret = PowerGetActiveScheme(NULL, &initial_powerprof); ok(ret == ERROR_SUCCESS, "Retrieval of inital power scheme failed: %lu\n", ret); - StringFromGUID2(initial_powerprof,guid_string, sizeof(guid_string));
/* Windows can have additional power schemes, wine currently cannot */ if(winetest_platform_is_wine) @@ -48,7 +46,7 @@ ok((IsEqualGUID(initial_powerprof,&GUID_MAX_POWER_SAVINGS) || IsEqualGUID(initial_powerprof,&GUID_TYPICAL_POWER_SAVINGS) || IsEqualGUID(initial_powerprof,&GUID_MIN_POWER_SAVINGS)), - "Initial powerscheme GUID is invalid: %ls\n", guid_string); + "Initial powerscheme GUID is invalid: %s\n", debugstr_guid(initial_powerprof)); } /* not testing setting 2nd parameter to NULL since that's an access violation on windows */ @@ -68,7 +66,8 @@
/* Test PowerSetActiveScheme with null */ ret = PowerSetActiveScheme(NULL,NULL); - ok(ret == ERROR_INVALID_PARAMETER, "PowerSetActiveScheme incorrectly return error code %lu\n", ret); + ok(ret == ERROR_INVALID_PARAMETER, + "PowerSetActiveScheme incorrectly return error code %lu\n", ret);
/* Try to actually change the power profile */ if (IsEqualGUID(initial_powerprof, &GUID_MIN_POWER_SAVINGS)) @@ -79,16 +78,18 @@ { new_powerprof = (GUID *) & GUID_MIN_POWER_SAVINGS; } - StringFromGUID2(new_powerprof,guid_string,sizeof(guid_string)); ret = PowerSetActiveScheme(NULL, new_powerprof); - ok(ret == ERROR_SUCCESS, "PowerSetActiveScheme failed setting to valid power scheme %ls: %lu\n", guid_string, ret); + ok(ret == ERROR_SUCCESS, + "PowerSetActiveScheme failed setting to valid power scheme %s, code: %lu\n", + debugstr_guid(new_powerprof), ret);
/* now try to retrieve it */ ret = PowerGetActiveScheme(NULL, &tmp_powerprof); - ok(ret == ERROR_SUCCESS, "Could not retrieve power scheme after setting it to %ls, code %lu\n", guid_string, ret); - StringFromGUID2(tmp_powerprof, guid_string2, sizeof(guid_string2)); - ok(IsEqualGUID(tmp_powerprof, new_powerprof), "Retrieved incorrect power profile after set: expected %ls, got %ls\n", - guid_string,guid_string2); + ok(ret == ERROR_SUCCESS, + "Could not retrieve power scheme after setting it to %s, code %lu\n", + debugstr_guid(new_powerprof), ret); + ok(IsEqualGUID(tmp_powerprof, new_powerprof), "Retrieved incorrect power profile after set: expected %s, got %s\n", + debugstr_guid(new_powerprof), debugstr_guid(tmp_powerprof)); LocalFree(tmp_powerprof);
/* try to set with non-NULL first parameter */
From: Robert Lippmann robert.lippmann.development@gmail.com
--- dlls/powrprof/powersetting.c | 10 +++++----- dlls/powrprof/tests/powersetting.c | 6 ++++-- 2 files changed, 9 insertions(+), 7 deletions(-)
diff --git a/dlls/powrprof/powersetting.c b/dlls/powrprof/powersetting.c index 1ffe8c65e3c..6219040b4c8 100644 --- a/dlls/powrprof/powersetting.c +++ b/dlls/powrprof/powersetting.c @@ -95,8 +95,8 @@ DWORD WINAPI PowerGetActiveScheme(HKEY UserRootPowerKey, GUID **polguid) { DWORD ret; HKEY hkey; - char scheme_guid[39]; - WCHAR scheme_guid_w[39]; + char scheme_guid[40]; + WCHAR scheme_guid_w[40]; DWORD scheme_guid_size = sizeof(scheme_guid);
TRACE("called\n"); @@ -106,7 +106,7 @@ DWORD WINAPI PowerGetActiveScheme(HKEY UserRootPowerKey, GUID **polguid) return ret; } /* Windows SDK docs say this can be freed with LocalFree() */ - *polguid = LocalAlloc(LPTR, sizeof(GUID)); + *polguid = LocalAlloc(LMEM_FIXED, sizeof(GUID)); if(*polguid == NULL) { return GetLastError(); @@ -121,7 +121,7 @@ DWORD WINAPI PowerGetActiveScheme(HKEY UserRootPowerKey, GUID **polguid) TRACE("RegQueryValueExA for %s returned %s\n", debugstr_a(active_power_scheme_value), debugstr_a(scheme_guid)); /* Windows SDK docs say this can be freed with LocalFree() */ - *polguid = LocalAlloc(LPTR, sizeof(GUID)); + *polguid = LocalAlloc(LMEM_FIXED, sizeof(GUID)); if(*polguid == NULL) { return GetLastError(); @@ -137,7 +137,7 @@ DWORD WINAPI PowerGetActiveScheme(HKEY UserRootPowerKey, GUID **polguid) /* Add curly braces around string */ scheme_guid_w[0] = L'{'; scheme_guid_w[ret] = L'}'; - scheme_guid[ret + 1] = L'\0'; + scheme_guid_w[ret+1] = L'\0'; TRACE("Converting GUID %s to CLSID\n", debugstr_w(scheme_guid_w)); ret = CLSIDFromString(scheme_guid_w, *polguid); if(ret != S_OK) diff --git a/dlls/powrprof/tests/powersetting.c b/dlls/powrprof/tests/powersetting.c index c3c1da6f292..b1067d47c27 100644 --- a/dlls/powrprof/tests/powersetting.c +++ b/dlls/powrprof/tests/powersetting.c @@ -24,7 +24,6 @@ #include "winreg.h" #include "objbase.h" #include "powersetting.h" - #include "wine/test.h"
START_TEST(powersetting) @@ -61,7 +60,10 @@ ret = PowerGetActiveScheme(tmp_key[i], &new_powerprof); ok(ret == ERROR_SUCCESS, "GetActivePowerScheme failed with HKEY %p\n", tmp_key[i]); - LocalFree(new_powerprof); + if(ret == ERROR_SUCCESS) + { + LocalFree(new_powerprof); + } }
/* Test PowerSetActiveScheme with null */
From: Robert Lippmann robert.lippmann.development@gmail.com
--- dlls/powrprof/powersetting.c | 25 ++++++++++++------------- dlls/powrprof/tests/powersetting.c | 21 ++++++++++----------- 2 files changed, 22 insertions(+), 24 deletions(-)
diff --git a/dlls/powrprof/powersetting.c b/dlls/powrprof/powersetting.c index 6219040b4c8..cafe6a3beec 100644 --- a/dlls/powrprof/powersetting.c +++ b/dlls/powrprof/powersetting.c @@ -28,7 +28,7 @@ WINE_DEFAULT_DEBUG_CHANNEL(powrprof);
-static const char active_power_scheme_key[] = +static const char active_power_scheme_key[] = "SYSTEM\CurrentControlSet\Control\Power\User\PowerSchemes"; static const char active_power_scheme_value[] = "ActivePowerScheme";
@@ -36,10 +36,10 @@ static const char active_power_scheme_value[] = "ActivePowerScheme"; static DWORD guid_to_registry(const GUID * const pguid, char *guid_str, int guid_str_size) { int ret; - + ret = snprintf(guid_str, guid_str_size, - "%08lX-%04X-%04X-%04X-%012llX", - pguid->Data1, pguid->Data2, + "%08lX-%04X-%04X-%04X-%012llX", + pguid->Data1, pguid->Data2, pguid->Data3, (pguid->Data4[0] << 8) | pguid->Data4[1], ((ULONGLONG)pguid->Data4[2] << 40) | @@ -47,7 +47,7 @@ static DWORD guid_to_registry(const GUID * const pguid, char *guid_str, int guid ((ULONGLONG)pguid->Data4[4] << 24) | ((ULONGLONG)pguid->Data4[5] << 16) | ((ULONGLONG)pguid->Data4[6] << 8) | - (ULONGLONG)pguid->Data4[7]); + (ULONGLONG)pguid->Data4[7]); if(ret >= guid_str_size) { ERR("Buffer overflow, expected %u bytes, got %u\n", guid_str_size, ret); @@ -106,11 +106,11 @@ DWORD WINAPI PowerGetActiveScheme(HKEY UserRootPowerKey, GUID **polguid) return ret; } /* Windows SDK docs say this can be freed with LocalFree() */ - *polguid = LocalAlloc(LMEM_FIXED, sizeof(GUID)); + *polguid = LocalAlloc(LMEM_FIXED, sizeof(GUID)); if(*polguid == NULL) { return GetLastError(); - } + } ret = RegQueryValueExA(hkey, active_power_scheme_value, NULL, NULL, (LPBYTE)scheme_guid, &scheme_guid_size); if(ret != ERROR_SUCCESS) { @@ -121,12 +121,12 @@ DWORD WINAPI PowerGetActiveScheme(HKEY UserRootPowerKey, GUID **polguid) TRACE("RegQueryValueExA for %s returned %s\n", debugstr_a(active_power_scheme_value), debugstr_a(scheme_guid)); /* Windows SDK docs say this can be freed with LocalFree() */ - *polguid = LocalAlloc(LMEM_FIXED, sizeof(GUID)); + *polguid = LocalAlloc(LMEM_FIXED, sizeof(GUID)); if(*polguid == NULL) { return GetLastError(); } - + ret = MultiByteToWideChar(CP_ACP, 0, scheme_guid, -1, scheme_guid_w + 1, scheme_guid_size); if (ret == 0) { @@ -142,7 +142,7 @@ DWORD WINAPI PowerGetActiveScheme(HKEY UserRootPowerKey, GUID **polguid) ret = CLSIDFromString(scheme_guid_w, *polguid); if(ret != S_OK) { - ERR("Converting GUID %s to CLSID failed, got error %ld\n", + ERR("Converting GUID %s to CLSID failed, got error %ld\n", debugstr_a(scheme_guid), ret); LocalFree(*polguid); return ERROR_INVALID_PARAMETER; @@ -150,7 +150,7 @@ DWORD WINAPI PowerGetActiveScheme(HKEY UserRootPowerKey, GUID **polguid) RegCloseKey(hkey); return ERROR_SUCCESS; } - + DWORD WINAPI PowerSetActiveScheme(HKEY UserRootPowerKey, GUID *polguid) { DWORD ret; @@ -179,7 +179,7 @@ DWORD WINAPI PowerSetActiveScheme(HKEY UserRootPowerKey, GUID *polguid) if(ret != ERROR_SUCCESS) { return ret; - } + } TRACE("Setting %s to %s\n", debugstr_a(active_power_scheme_value), debugstr_a(scheme_guid)); ret=RegSetValueExA(hkey, active_power_scheme_value, 0, REG_SZ, (const BYTE *)scheme_guid, strlen(scheme_guid) + 1); if(ret != ERROR_SUCCESS) @@ -190,4 +190,3 @@ DWORD WINAPI PowerSetActiveScheme(HKEY UserRootPowerKey, GUID *polguid) RegCloseKey(hkey); return ERROR_SUCCESS; } - \ No newline at end of file diff --git a/dlls/powrprof/tests/powersetting.c b/dlls/powrprof/tests/powersetting.c index b1067d47c27..825a9bd885c 100644 --- a/dlls/powrprof/tests/powersetting.c +++ b/dlls/powrprof/tests/powersetting.c @@ -30,7 +30,7 @@ { GUID *initial_powerprof = NULL, *new_powerprof = NULL, *tmp_powerprof = NULL; HKEY tmp_key[] = { HKEY_CLASSES_ROOT, HKEY_CURRENT_CONFIG, HKEY_CURRENT_USER, - HKEY_DYN_DATA, HKEY_LOCAL_MACHINE, HKEY_PERFORMANCE_DATA, + HKEY_DYN_DATA, HKEY_LOCAL_MACHINE, HKEY_PERFORMANCE_DATA, HKEY_PERFORMANCE_NLSTEXT, HKEY_USERS }; DWORD ret; register int i; @@ -38,7 +38,7 @@ /* save initial power scheme to restore when test is finished */ ret = PowerGetActiveScheme(NULL, &initial_powerprof); ok(ret == ERROR_SUCCESS, "Retrieval of inital power scheme failed: %lu\n", ret); - + /* Windows can have additional power schemes, wine currently cannot */ if(winetest_platform_is_wine) { @@ -47,10 +47,10 @@ IsEqualGUID(initial_powerprof,&GUID_MIN_POWER_SAVINGS)), "Initial powerscheme GUID is invalid: %s\n", debugstr_guid(initial_powerprof)); } - /* not testing setting 2nd parameter to NULL since that's an + /* not testing setting 2nd parameter to NULL since that's an access violation on windows */
- /* Win32 docs say that the first parameter of PowerGetActiveScheme should be NULL, + /* Win32 docs say that the first parameter of PowerGetActiveScheme should be NULL, but Windows appears to ignore it rather than throw an error. So, we'll test with all the predefined HKEYs to allow for regression in case this changes. @@ -65,10 +65,10 @@ LocalFree(new_powerprof); } } - + /* Test PowerSetActiveScheme with null */ ret = PowerSetActiveScheme(NULL,NULL); - ok(ret == ERROR_INVALID_PARAMETER, + ok(ret == ERROR_INVALID_PARAMETER, "PowerSetActiveScheme incorrectly return error code %lu\n", ret);
/* Try to actually change the power profile */ @@ -81,19 +81,19 @@ new_powerprof = (GUID *) & GUID_MIN_POWER_SAVINGS; } ret = PowerSetActiveScheme(NULL, new_powerprof); - ok(ret == ERROR_SUCCESS, - "PowerSetActiveScheme failed setting to valid power scheme %s, code: %lu\n", + ok(ret == ERROR_SUCCESS, + "PowerSetActiveScheme failed setting to valid power scheme %s, code: %lu\n", debugstr_guid(new_powerprof), ret);
/* now try to retrieve it */ ret = PowerGetActiveScheme(NULL, &tmp_powerprof); - ok(ret == ERROR_SUCCESS, + ok(ret == ERROR_SUCCESS, "Could not retrieve power scheme after setting it to %s, code %lu\n", debugstr_guid(new_powerprof), ret); ok(IsEqualGUID(tmp_powerprof, new_powerprof), "Retrieved incorrect power profile after set: expected %s, got %s\n", debugstr_guid(new_powerprof), debugstr_guid(tmp_powerprof)); LocalFree(tmp_powerprof); - + /* try to set with non-NULL first parameter */ for (i = 0; i < ARRAYSIZE(tmp_key); i++) { @@ -107,4 +107,3 @@ LocalFree(initial_powerprof);
} - \ No newline at end of file
From: Robert Lippmann robert.lippmann.development@gmail.com
--- include/winnt.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/include/winnt.h b/include/winnt.h index 6737c0f85ac..c30b6937009 100644 --- a/include/winnt.h +++ b/include/winnt.h @@ -4326,7 +4326,7 @@ typedef struct _ACL {
typedef enum _ACL_INFORMATION_CLASS { - AclRevisionInformation = 1, + AclRevisionInformation = 1, AclSizeInformation } ACL_INFORMATION_CLASS;
This also implements stubs for power related Win32 sdk functions introduced in Windows Vista.
Hi, @rlippmann. This needs some basic cleanup first - fixup commits should be merged with main commits so that MR has a clean list of wellformed changes. Note that you don't need to create a new MR every time you want to change something. Just force push to the same branch.
This merge request was closed by Robert Lippmann.
Nikolay Sivov (@nsivov) commented about dlls/powrprof/powrprof.spec:
-@ stdcall PowerReadFriendlyName (ptr ptr ptr ptr ptr ptr) -@ stdcall PowerRegisterSuspendResumeNotification(long ptr ptr) -@ stdcall PowerUnregisterSuspendResumeNotification(ptr) -@ stdcall PowerSettingRegisterNotification(ptr long ptr ptr) -@ stdcall PowerSettingUnregisterNotification(ptr) -@ stdcall PowerWriteACValueIndex(ptr ptr ptr ptr long) -@ stdcall ReadGlobalPwrPolicy (ptr) -@ stdcall ReadProcessorPwrScheme (long ptr) -@ stdcall ReadPwrScheme (long ptr) -@ stdcall SetActivePwrScheme (long ptr ptr) -@ stdcall SetSuspendState (long long long) -@ stdcall WriteGlobalPwrPolicy (ptr) -@ stdcall WriteProcessorPwrScheme (long ptr) -@ stdcall WritePwrScheme (ptr str str ptr) +1 stdcall CallNtPowerInformation( ptr ptr long ptr long ) +2 stdcall CanUserWritePwrScheme()
Why do you need this?
Nikolay Sivov (@nsivov) commented about dlls/powrprof/Makefile.in:
IMPORTS = advapi32
SOURCES = \
- powrprof.c
- powrprof.c \
- powersetting.c
You probably don't need a new file for this.
Nikolay Sivov (@nsivov) commented about include/powersetting.h:
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
- This library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
- You should have received a copy of the GNU Lesser General Public
- License along with this library; if not, write to the Free Software
- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
- */
+#ifndef _POWERSETTING_H +#define _POWERSETTING_H 1
Usually guards are not used with a value like that.
Do you have an application that depends on those functions returning anything?