windowscodecs: Silence fixme for IID_CMetaBitmapRenderTarget.
[wine.git] / dlls / powrprof / powrprof.c
blobdcc7126b920fbfa45d68baa68224e40a89bd5d15
1 /*
2 * Copyright (C) 2005 Benjamin Cutler
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #include <stdarg.h>
21 #include <stdlib.h>
23 #include "ntstatus.h"
24 #define WIN32_NO_STATUS
25 #include "windef.h"
26 #include "winbase.h"
27 #include "winnt.h"
28 #include "winreg.h"
29 #include "winternl.h"
30 #include "powrprof.h"
31 #include "wine/debug.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(powrprof);
35 /* Notes to implementors:
36 * #1: The native implementation of these functions attempted to read in
37 * registry entries that I was unable to locate on any of the Windows
38 * machines I checked, but I only had desktops available, so maybe
39 * laptop users will have better luck. They return FNF errors because
40 * that's what the native DLL was returning during my tests.
41 * #2: These functions call NtPowerInformation but I don't know what they
42 * do with the results, and NtPowerInformation doesn't do much in WINE yet
43 * anyway.
44 * #3: Since I can't get several other functions working (see note #1),
45 * implementing these functions is going to have to wait until somebody can
46 * cobble together some sane test input. */
48 static const WCHAR szPowerCfgSubKey[] = L"Software\\Microsoft\\Windows\\CurrentVersion\\Controls Folder\\PowerCfg";
49 static HANDLE PPRegSemaphore = NULL;
51 NTSTATUS WINAPI CallNtPowerInformation(
52 POWER_INFORMATION_LEVEL InformationLevel,
53 PVOID lpInputBuffer, ULONG nInputBufferSize,
54 PVOID lpOutputBuffer, ULONG nOutputBufferSize)
56 return NtPowerInformation(InformationLevel, lpInputBuffer,
57 nInputBufferSize, lpOutputBuffer, nOutputBufferSize);
60 BOOLEAN WINAPI CanUserWritePwrScheme(VOID)
62 HKEY hKey = NULL;
63 LONG r;
64 BOOLEAN bSuccess = TRUE;
66 TRACE("()\n");
68 r = RegOpenKeyExW(HKEY_LOCAL_MACHINE, szPowerCfgSubKey, 0, KEY_READ | KEY_WRITE, &hKey);
70 if (r != ERROR_SUCCESS) {
71 TRACE("RegOpenKeyEx failed: %ld\n", r);
72 bSuccess = FALSE;
75 SetLastError(r);
76 RegCloseKey(hKey);
77 return bSuccess;
80 BOOLEAN WINAPI DeletePwrScheme(UINT uiIndex)
82 /* FIXME: See note #1 */
83 FIXME("(%d) stub!\n", uiIndex);
84 SetLastError(ERROR_FILE_NOT_FOUND);
85 return FALSE;
88 BOOLEAN WINAPI EnumPwrSchemes(PWRSCHEMESENUMPROC lpfnPwrSchemesEnumProc,
89 LPARAM lParam)
91 /* FIXME: See note #1 */
92 FIXME("(%p, %Id) stub!\n", lpfnPwrSchemesEnumProc, lParam);
93 SetLastError(ERROR_FILE_NOT_FOUND);
94 return FALSE;
97 BOOLEAN WINAPI GetActivePwrScheme(PUINT puiID)
99 /* FIXME: See note #1 */
100 FIXME("(%p) stub!\n", puiID);
101 SetLastError(ERROR_FILE_NOT_FOUND);
102 return FALSE;
105 BOOLEAN WINAPI GetCurrentPowerPolicies(
106 PGLOBAL_POWER_POLICY pGlobalPowerPolicy,
107 PPOWER_POLICY pPowerPolicy)
109 /* FIXME: See note #2 */
110 SYSTEM_POWER_POLICY ACPower, DCPower;
112 FIXME("(%p, %p) stub!\n", pGlobalPowerPolicy, pPowerPolicy);
114 NtPowerInformation(SystemPowerPolicyAc, 0, 0, &ACPower, sizeof(SYSTEM_POWER_POLICY));
115 NtPowerInformation(SystemPowerPolicyDc, 0, 0, &DCPower, sizeof(SYSTEM_POWER_POLICY));
117 return FALSE;
120 BOOLEAN WINAPI GetPwrCapabilities(
121 PSYSTEM_POWER_CAPABILITIES lpSystemPowerCapabilities)
123 NTSTATUS r;
125 TRACE("(%p)\n", lpSystemPowerCapabilities);
127 r = NtPowerInformation(SystemPowerCapabilities, 0, 0, lpSystemPowerCapabilities, sizeof(SYSTEM_POWER_CAPABILITIES));
129 SetLastError(RtlNtStatusToDosError(r));
131 return r == STATUS_SUCCESS;
134 BOOLEAN WINAPI GetPwrDiskSpindownRange(PUINT RangeMax, PUINT RangeMin)
136 HKEY hKey;
137 BYTE lpValue[40];
138 LONG r;
139 DWORD cbValue = sizeof(lpValue);
141 TRACE("(%p, %p)\n", RangeMax, RangeMin);
143 if (RangeMax == NULL || RangeMin == NULL) {
144 SetLastError(ERROR_INVALID_PARAMETER);
145 return FALSE;
148 SetLastError(ERROR_SUCCESS);
150 WaitForSingleObject(PPRegSemaphore, INFINITE);
152 r = RegOpenKeyExW(HKEY_LOCAL_MACHINE, szPowerCfgSubKey, 0, KEY_READ, &hKey);
153 if (r != ERROR_SUCCESS) {
154 TRACE("RegOpenKeyEx failed: %ld\n", r);
155 TRACE("Using defaults: 3600, 3\n");
156 *RangeMax = 3600;
157 *RangeMin = 3;
158 ReleaseSemaphore(PPRegSemaphore, 1, NULL);
159 return TRUE;
162 r = RegQueryValueExW(hKey, L"DiskSpindownMax", 0, 0, lpValue, &cbValue);
163 if (r != ERROR_SUCCESS) {
164 TRACE("Couldn't open DiskSpinDownMax: %ld\n", r);
165 TRACE("Using default: 3600\n");
166 *RangeMax = 3600;
167 } else {
168 *RangeMax = wcstol((LPCWSTR)lpValue, NULL, 10);
171 cbValue = sizeof(lpValue);
173 r = RegQueryValueExW(hKey, L"DiskSpindownMin", 0, 0, lpValue, &cbValue);
174 if (r != ERROR_SUCCESS) {
175 TRACE("Couldn't open DiskSpinDownMin: %ld\n", r);
176 TRACE("Using default: 3\n");
177 *RangeMin = 3;
178 } else {
179 *RangeMin = wcstol((LPCWSTR)lpValue, NULL, 10);
182 RegCloseKey(hKey);
184 ReleaseSemaphore(PPRegSemaphore, 1, NULL);
186 return TRUE;
189 BOOLEAN WINAPI IsAdminOverrideActive(PADMINISTRATOR_POWER_POLICY p)
191 FIXME("( %p) stub!\n", p);
192 return FALSE;
195 BOOLEAN WINAPI IsPwrHibernateAllowed(VOID)
197 SYSTEM_POWER_CAPABILITIES PowerCaps;
198 NtPowerInformation(SystemPowerCapabilities, NULL, 0, &PowerCaps, sizeof(PowerCaps));
199 return PowerCaps.SystemS4 && PowerCaps.HiberFilePresent;
202 BOOLEAN WINAPI IsPwrShutdownAllowed(VOID)
204 SYSTEM_POWER_CAPABILITIES PowerCaps;
205 NtPowerInformation(SystemPowerCapabilities, NULL, 0, &PowerCaps, sizeof(PowerCaps));
206 return PowerCaps.SystemS5;
209 BOOLEAN WINAPI IsPwrSuspendAllowed(VOID)
211 SYSTEM_POWER_CAPABILITIES PowerCaps;
212 NtPowerInformation(SystemPowerCapabilities, NULL, 0, &PowerCaps, sizeof(PowerCaps));
213 return PowerCaps.SystemS1 && PowerCaps.SystemS2 && PowerCaps.SystemS3;
216 BOOLEAN WINAPI ReadGlobalPwrPolicy(PGLOBAL_POWER_POLICY pGlobalPowerPolicy)
218 /* FIXME: See note #1 */
219 FIXME("(%p) stub!\n", pGlobalPowerPolicy);
220 SetLastError(ERROR_FILE_NOT_FOUND);
221 return FALSE;
224 BOOLEAN WINAPI ReadProcessorPwrScheme(UINT uiID,
225 PMACHINE_PROCESSOR_POWER_POLICY pMachineProcessorPowerPolicy)
227 /* FIXME: See note #1 */
228 FIXME("(%d, %p) stub!\n", uiID, pMachineProcessorPowerPolicy);
229 SetLastError(ERROR_FILE_NOT_FOUND);
230 return FALSE;
233 BOOLEAN WINAPI ReadPwrScheme(UINT uiID,
234 PPOWER_POLICY pPowerPolicy)
236 /* FIXME: See note #1 */
237 FIXME("(%d, %p) stub!\n", uiID, pPowerPolicy);
238 SetLastError(ERROR_FILE_NOT_FOUND);
239 return FALSE;
242 BOOLEAN WINAPI SetActivePwrScheme(UINT uiID,
243 PGLOBAL_POWER_POLICY lpGlobalPowerPolicy,
244 PPOWER_POLICY lpPowerPolicy)
246 /* FIXME: See note #1 */
247 FIXME("(%d, %p, %p) stub!\n", uiID, lpGlobalPowerPolicy, lpPowerPolicy);
248 SetLastError(ERROR_FILE_NOT_FOUND);
249 return FALSE;
252 BOOLEAN WINAPI SetSuspendState(BOOLEAN Hibernate, BOOLEAN ForceCritical,
253 BOOLEAN DisableWakeEvent)
255 /* FIXME: I have NO idea how you're supposed to call NtInitiatePowerAction
256 * here, because it's not a documented function that I can find */
257 FIXME("(%d, %d, %d) stub!\n", Hibernate, ForceCritical, DisableWakeEvent);
258 return TRUE;
261 BOOLEAN WINAPI WriteGlobalPwrPolicy(PGLOBAL_POWER_POLICY pGlobalPowerPolicy)
263 /* FIXME: See note #3 */
264 FIXME("(%p) stub!\n", pGlobalPowerPolicy);
265 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
266 return FALSE;
269 BOOLEAN WINAPI WriteProcessorPwrScheme(UINT ID,
270 PMACHINE_PROCESSOR_POWER_POLICY pMachineProcessorPowerPolicy)
272 /* FIXME: See note #3 */
273 FIXME("(%d, %p) stub!\n", ID, pMachineProcessorPowerPolicy);
274 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
275 return FALSE;
278 BOOLEAN WINAPI WritePwrScheme(PUINT puiID, LPWSTR lpszName, LPWSTR lpszDescription,
279 PPOWER_POLICY pPowerPolicy)
281 /* FIXME: See note #3 */
282 FIXME("(%p, %s, %s, %p) stub!\n", puiID, debugstr_w(lpszName), debugstr_w(lpszDescription), pPowerPolicy);
283 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
284 return FALSE;
287 DWORD WINAPI PowerGetActiveScheme(HKEY UserRootPowerKey, GUID **polguid)
289 FIXME("(%p,%p) stub!\n", UserRootPowerKey, polguid);
290 return ERROR_CALL_NOT_IMPLEMENTED;
293 DWORD WINAPI PowerSetActiveScheme(HKEY UserRootPowerKey, GUID *polguid)
295 FIXME("(%p,%s) stub!\n", UserRootPowerKey, wine_dbgstr_guid(polguid));
296 return ERROR_SUCCESS;
299 DWORD WINAPI PowerReadDCValue(HKEY RootPowerKey, const GUID *Scheme, const GUID *SubGroup, const GUID *PowerSettings, PULONG Type, PUCHAR Buffer, DWORD *BufferSize)
301 FIXME("(%p,%s,%s,%s,%p,%p,%p) stub!\n", RootPowerKey, debugstr_guid(Scheme), debugstr_guid(SubGroup), debugstr_guid(PowerSettings), Type, Buffer, BufferSize);
302 return ERROR_CALL_NOT_IMPLEMENTED;
305 DWORD WINAPI PowerReadFriendlyName(HKEY RootPowerKey, const GUID *Scheme,
306 const GUID *SubGroup, const GUID *PowerSettings, UCHAR *Buffer,
307 DWORD *BufferSize)
309 FIXME("(%p,%s,%s,%s,%p,%p) stub!\n", RootPowerKey, debugstr_guid(Scheme), debugstr_guid(SubGroup), debugstr_guid(PowerSettings), Buffer, BufferSize);
310 return ERROR_CALL_NOT_IMPLEMENTED;
313 POWER_PLATFORM_ROLE WINAPI PowerDeterminePlatformRole(void)
315 FIXME("stub\n");
316 return PlatformRoleDesktop;
319 POWER_PLATFORM_ROLE WINAPI PowerDeterminePlatformRoleEx(ULONG version)
321 FIXME("%lu stub.\n", version);
322 return PlatformRoleDesktop;
325 DWORD WINAPI PowerEnumerate(HKEY key, const GUID *scheme, const GUID *subgroup, POWER_DATA_ACCESSOR flags,
326 ULONG index, UCHAR *buffer, DWORD *buffer_size)
328 FIXME("(%p,%s,%s,%d,%ld,%p,%p) stub!\n", key, debugstr_guid(scheme), debugstr_guid(subgroup),
329 flags, index, buffer, buffer_size);
330 return ERROR_CALL_NOT_IMPLEMENTED;
333 DWORD WINAPI PowerRegisterSuspendResumeNotification(DWORD flags, HANDLE recipient, PHPOWERNOTIFY handle)
335 FIXME("(0x%08lx,%p,%p) stub!\n", flags, recipient, handle);
336 *handle = (HPOWERNOTIFY)0xdeadbeef;
337 return ERROR_SUCCESS;
340 DWORD WINAPI PowerUnregisterSuspendResumeNotification(HPOWERNOTIFY handle)
342 FIXME("(%p) stub!\n", handle);
343 return ERROR_SUCCESS;
346 DWORD WINAPI PowerSettingRegisterNotification(const GUID *setting, DWORD flags, HANDLE recipient, PHPOWERNOTIFY handle)
348 FIXME("(%s,0x%08lx,%p,%p) stub!\n", debugstr_guid(setting), flags, recipient, handle);
349 *handle = (PHPOWERNOTIFY)0xdeadbeef;
350 return ERROR_SUCCESS;
353 DWORD WINAPI PowerSettingUnregisterNotification(HPOWERNOTIFY handle)
355 FIXME("(%p) stub!\n", handle);
356 return ERROR_SUCCESS;
359 DWORD WINAPI PowerWriteACValueIndex(HKEY key, const GUID *scheme, const GUID *subgroup, const GUID *setting, DWORD index)
361 FIXME("(%p,%s,%s,%s,0x%08lx) stub!\n", key, debugstr_guid(scheme), debugstr_guid(subgroup), debugstr_guid(setting), index);
362 return ERROR_SUCCESS;
365 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
367 switch(fdwReason) {
368 case DLL_PROCESS_ATTACH: {
370 HKEY hKey;
371 LONG r;
373 DisableThreadLibraryCalls(hinstDLL);
375 r = RegOpenKeyExW(HKEY_LOCAL_MACHINE, szPowerCfgSubKey, 0, KEY_READ | KEY_WRITE, &hKey);
377 if (r != ERROR_SUCCESS) {
378 TRACE("Couldn't open registry key HKLM\\%s, using some sane(?) defaults\n", debugstr_w(szPowerCfgSubKey));
379 } else {
380 BYTE lpValue[40];
381 DWORD cbValue = sizeof(lpValue);
382 r = RegQueryValueExW(hKey, L"LastID", 0, 0, lpValue, &cbValue);
383 if (r != ERROR_SUCCESS) {
384 TRACE("Couldn't open registry entry HKLM\\%s\\LastID, using some sane(?) defaults\n", debugstr_w(szPowerCfgSubKey));
386 RegCloseKey(hKey);
389 PPRegSemaphore = CreateSemaphoreW(NULL, 1, 1, L"PowerProfileRegistrySemaphore");
390 if (PPRegSemaphore == NULL) {
391 ERR("Couldn't create Semaphore: %ld\n", GetLastError());
392 return FALSE;
394 break;
396 case DLL_PROCESS_DETACH:
397 if (lpvReserved) break;
398 CloseHandle(PPRegSemaphore);
399 break;
401 return TRUE;