The real, definitive, Visual C++ support branch. Accept no substitutes
[reactos.git] / dll / win32 / powrprof / powrprof.c
1 /*
2 * Copyright (C) 2005 Benjamin Cutler
3 * Copyright (C) 2008 Dmitry Chapyshev
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
18 */
19
20
21 #include <stdarg.h>
22
23 #include <ntstatus.h>
24 #define WIN32_NO_STATUS
25 #include <windows.h>
26 #include <winternl.h>
27 #include <powrprof.h>
28 #include <wchar.h>
29 #include <stdio.h>
30
31 #include "wine/debug.h"
32
33 WINE_DEFAULT_DEBUG_CHANNEL(powrprof);
34
35
36 static const WCHAR szPowerCfgSubKey[] =
37 L"Software\\Microsoft\\Windows\\CurrentVersion\\Controls Folder\\PowerCfg";
38 static const WCHAR szPolicies[] = L"Policies";
39 static const WCHAR szSemaphoreName[] = L"PowerProfileRegistrySemaphore";
40 static const WCHAR szDiskMax[] = L"DiskSpindownMax";
41 static const WCHAR szDiskMin[] = L"DiskSpindownMin";
42 static const WCHAR szLastID[] = L"LastID";
43
44 HANDLE PPRegSemaphore = NULL;
45
46 NTSTATUS WINAPI
47 CallNtPowerInformation(POWER_INFORMATION_LEVEL InformationLevel,
48 PVOID lpInputBuffer,
49 ULONG nInputBufferSize,
50 PVOID lpOutputBuffer,
51 ULONG nOutputBufferSize)
52 {
53 return NtPowerInformation(InformationLevel,
54 lpInputBuffer,
55 nInputBufferSize,
56 lpOutputBuffer,
57 nOutputBufferSize);
58 }
59
60
61 BOOLEAN WINAPI
62 CanUserWritePwrScheme(VOID)
63 {
64 HKEY hKey = NULL;
65 LONG Ret;
66 BOOLEAN bSuccess = TRUE;
67
68 TRACE("()\n");
69
70 Ret = RegOpenKeyExW(HKEY_LOCAL_MACHINE, szPowerCfgSubKey, 0, KEY_READ | KEY_WRITE, &hKey);
71
72 if (Ret != ERROR_SUCCESS)
73 {
74 TRACE("RegOpenKeyEx failed: %d\n", Ret);
75 bSuccess = FALSE;
76 }
77
78 SetLastError(Ret);
79 RegCloseKey(hKey);
80 return bSuccess;
81 }
82
83
84 BOOLEAN WINAPI
85 DeletePwrScheme(UINT uiIndex)
86 {
87 WCHAR Buf[MAX_PATH];
88 UINT Current;
89 LONG Err;
90
91 swprintf(Buf, L"Control Panel\\PowerCfg\\PowerPolicies\\%d", uiIndex);
92
93 if (GetActivePwrScheme(&Current))
94 {
95 if (Current == uiIndex)
96 {
97 SetLastError(ERROR_ACCESS_DENIED);
98 return FALSE;
99 }
100 else
101 {
102 Err = RegDeleteKey(HKEY_CURRENT_USER, (LPCTSTR) Buf);
103 if (Err != ERROR_SUCCESS)
104 {
105 TRACE("RegDeleteKey failed: %d\n", Err);
106 SetLastError(Err);
107 return FALSE;
108 }
109 else
110 {
111 SetLastError(ERROR_SUCCESS);
112 return TRUE;
113 }
114 }
115 }
116
117 return FALSE;
118 }
119
120
121 static BOOLEAN
122 POWRPROF_GetUserPowerPolicy(LPWSTR szNum,
123 PUSER_POWER_POLICY puserPwrPolicy,
124 DWORD dwName, LPWSTR szName,
125 DWORD dwDesc, LPWSTR szDesc)
126 {
127 HKEY hSubKey;
128 DWORD dwSize;
129 LONG Err;
130 WCHAR szPath[MAX_PATH];
131
132 swprintf(szPath, L"Control Panel\\PowerCfg\\PowerPolicies\\%s", szNum);
133
134 Err = RegOpenKeyW(HKEY_CURRENT_USER, szPath, &hSubKey);
135 if (Err != ERROR_SUCCESS)
136 {
137 ERR("RegOpenKeyW failed: %d\n", Err);
138 SetLastError(Err);
139 return FALSE;
140 }
141
142 dwName = MAX_PATH * sizeof(WCHAR);
143 Err = RegQueryValueExW(hSubKey, L"Name", NULL, NULL, (LPBYTE)szName, &dwName);
144 if (Err != ERROR_SUCCESS)
145 {
146 ERR("RegQueryValueExW failed: %d\n", Err);
147 SetLastError(Err);
148 return FALSE;
149 }
150
151 dwDesc = MAX_PATH * sizeof(WCHAR);
152 Err = RegQueryValueExW(hSubKey, L"Description", NULL, NULL, (LPBYTE)szDesc, &dwDesc);
153 if (Err != ERROR_SUCCESS)
154 {
155 ERR("RegQueryValueExW failed: %d\n", Err);
156 SetLastError(Err);
157 return FALSE;
158 }
159
160 dwSize = sizeof(USER_POWER_POLICY);
161 Err = RegQueryValueExW(hSubKey, L"Policies", NULL, NULL, (LPBYTE)puserPwrPolicy, &dwSize);
162 if (Err != ERROR_SUCCESS)
163 {
164 ERR("RegQueryValueExW failed: %d\n", Err);
165 SetLastError(Err);
166 return FALSE;
167 }
168
169 return TRUE;
170 }
171
172 static BOOLEAN
173 POWRPROF_GetMachinePowerPolicy(LPWSTR szNum, PMACHINE_POWER_POLICY pmachinePwrPolicy)
174 {
175 HKEY hKey;
176 LONG Err;
177 WCHAR szPath[MAX_PATH];
178 DWORD dwSize;
179
180 swprintf(szPath, L"Software\\Microsoft\\Windows\\CurrentVersion\\Controls Folder\\PowerCfg\\PowerPolicies\\%s", szNum);
181
182 Err = RegOpenKeyW(HKEY_LOCAL_MACHINE, szPath, &hKey);
183 if (Err != ERROR_SUCCESS)
184 {
185 ERR("RegOpenKeyW failed: %d\n", Err);
186 SetLastError(Err);
187 return FALSE;
188 }
189
190 dwSize = sizeof(MACHINE_POWER_POLICY);
191 Err = RegQueryValueExW(hKey, L"Policies", NULL, NULL, (LPBYTE)pmachinePwrPolicy, &dwSize);
192 if (Err != ERROR_SUCCESS)
193 {
194 ERR("RegQueryValueExW failed: %d\n", Err);
195 SetLastError(Err);
196 return FALSE;
197 }
198
199 return TRUE;
200 }
201
202 BOOLEAN WINAPI
203 EnumPwrSchemes(PWRSCHEMESENUMPROC lpfnPwrSchemesEnumProc,
204 LPARAM lParam)
205 {
206 HKEY hKey;
207 LONG Err;
208 DWORD dwSize, dwNameSize = MAX_PATH, dwDescSize = MAX_PATH, dwIndex = 0;
209 WCHAR szNum[3 + 1], szName[MAX_PATH], szDesc[MAX_PATH];
210 POWER_POLICY PwrPolicy;
211 USER_POWER_POLICY userPwrPolicy;
212 MACHINE_POWER_POLICY machinePwrPolicy;
213 BOOLEAN ret = FALSE;
214
215 if (!lpfnPwrSchemesEnumProc)
216 {
217 SetLastError(ERROR_INVALID_PARAMETER);
218 return FALSE;
219 }
220
221 Err = RegOpenKeyW(HKEY_CURRENT_USER, L"Control Panel\\PowerCfg\\PowerPolicies", &hKey);
222 if (Err != ERROR_SUCCESS)
223 {
224 ERR("RegOpenKeyW failed: %d\n", Err);
225 SetLastError(Err);
226 return FALSE;
227 }
228
229 ReleaseSemaphore(PPRegSemaphore, 1, NULL);
230
231 dwSize = sizeof(szNum) / sizeof(WCHAR);
232
233 while (RegEnumKeyExW(hKey, dwIndex, szNum, &dwSize, NULL, NULL, NULL, NULL) == ERROR_SUCCESS)
234 {
235 if (!POWRPROF_GetUserPowerPolicy(szNum, &userPwrPolicy,
236 dwNameSize, szName,
237 dwDescSize, szDesc))
238 {
239 RegCloseKey(hKey);
240 ReleaseSemaphore(PPRegSemaphore, 1, NULL);
241 return FALSE;
242 }
243
244 if (!POWRPROF_GetMachinePowerPolicy(szNum, &machinePwrPolicy))
245 {
246 RegCloseKey(hKey);
247 ReleaseSemaphore(PPRegSemaphore, 1, NULL);
248 return FALSE;
249 }
250
251 memcpy(&PwrPolicy.user, &userPwrPolicy, sizeof(USER_POWER_POLICY));
252 memcpy(&PwrPolicy.mach, &machinePwrPolicy, sizeof(MACHINE_POWER_POLICY));
253
254 if (!lpfnPwrSchemesEnumProc(_wtoi(szNum), dwNameSize, szName, dwDescSize, szDesc, &PwrPolicy, lParam))
255 {
256 RegCloseKey(hKey);
257 ReleaseSemaphore(PPRegSemaphore, 1, NULL);
258 return ret;
259 }
260 else
261 {
262 ret=TRUE;
263 }
264
265 dwSize = sizeof(szNum) / sizeof(WCHAR);
266 dwIndex++;
267 }
268
269 RegCloseKey(hKey);
270 ReleaseSemaphore(PPRegSemaphore, 1, NULL);
271 SetLastError(ERROR_SUCCESS);
272
273 return TRUE;
274 }
275
276
277 BOOLEAN WINAPI
278 GetActivePwrScheme(PUINT puiID)
279 {
280 HKEY hKey;
281 WCHAR szBuf[MAX_PATH];
282 DWORD dwSize;
283 LONG Err;
284
285 TRACE("GetActivePwrScheme(%u)", puiID);
286
287 Err = RegOpenKeyW(HKEY_CURRENT_USER, L"Control Panel\\PowerCfg", &hKey);
288 if (Err != ERROR_SUCCESS)
289 {
290 ERR("RegOpenKey failed: %d\n", Err);
291 SetLastError(Err);
292 return FALSE;
293 }
294
295 dwSize = MAX_PATH;
296 Err = RegQueryValueExW(hKey, L"CurrentPowerPolicy",
297 NULL, NULL,
298 (LPBYTE)&szBuf, &dwSize);
299 if (Err != ERROR_SUCCESS)
300 {
301 ERR("RegQueryValueEx failed: %d\n", Err);
302 RegCloseKey(hKey);
303 SetLastError(Err);
304 return FALSE;
305 }
306
307 *puiID = _wtoi(szBuf);
308
309 RegCloseKey(hKey);
310 SetLastError(ERROR_SUCCESS);
311 return TRUE;
312 }
313
314
315 BOOLEAN WINAPI
316 GetCurrentPowerPolicies(PGLOBAL_POWER_POLICY pGlobalPowerPolicy,
317 PPOWER_POLICY pPowerPolicy)
318 {
319 /*
320 SYSTEM_POWER_POLICY ACPower, DCPower;
321
322 FIXME("(%p, %p) stub!\n", pGlobalPowerPolicy, pPowerPolicy);
323
324 NtPowerInformation(SystemPowerPolicyAc, 0, 0, &ACPower, sizeof(SYSTEM_POWER_POLICY));
325 NtPowerInformation(SystemPowerPolicyDc, 0, 0, &DCPower, sizeof(SYSTEM_POWER_POLICY));
326
327 return FALSE;
328 */
329 /*
330 Lohnegrim: I dont know why this Function shoud call NtPowerInformation, becouse as far as i know,
331 it simply returns the GlobalPowerPolicy and the AktivPowerScheme!
332 */
333 BOOLEAN ret;
334 UINT uiID;
335
336 if (pGlobalPowerPolicy != NULL)
337 {
338 ret = ReadGlobalPwrPolicy(pGlobalPowerPolicy);
339 if (!ret)
340 {
341 return FALSE;
342 }
343 }
344 if (pPowerPolicy != NULL)
345 {
346 ret = GetActivePwrScheme(&uiID);
347 if (!ret)
348 {
349 return FALSE;
350 }
351 ret = ReadPwrScheme(uiID,pPowerPolicy);
352 if (!ret)
353 {
354 return FALSE;
355 }
356 }
357 return TRUE;
358 }
359
360
361 BOOLEAN WINAPI
362 GetPwrCapabilities(PSYSTEM_POWER_CAPABILITIES lpSystemPowerCapabilities)
363 {
364 NTSTATUS Ret;
365
366 TRACE("(%p)\n", lpSystemPowerCapabilities);
367
368 if (!lpSystemPowerCapabilities)
369 {
370 SetLastError(ERROR_INVALID_PARAMETER);
371 return FALSE;
372 }
373
374 Ret = NtPowerInformation(SystemPowerCapabilities, 0, 0, lpSystemPowerCapabilities, sizeof(SYSTEM_POWER_CAPABILITIES));
375
376 SetLastError(RtlNtStatusToDosError(Ret));
377
378 if (Ret == STATUS_SUCCESS)
379 return TRUE;
380 else
381 return FALSE;
382 }
383
384
385 BOOLEAN WINAPI
386 GetPwrDiskSpindownRange(PUINT RangeMax, PUINT RangeMin)
387 {
388 HKEY hKey;
389 BYTE lpValue[40];
390 LONG Ret;
391 DWORD cbValue = sizeof(lpValue);
392
393 TRACE("(%p, %p)\n", RangeMax, RangeMin);
394
395 if (RangeMax == NULL || RangeMin == NULL)
396 {
397 SetLastError(ERROR_INVALID_PARAMETER);
398 return FALSE;
399 }
400
401 SetLastError(ERROR_SUCCESS);
402
403 WaitForSingleObject(PPRegSemaphore, INFINITE);
404
405 Ret = RegOpenKeyExW(HKEY_LOCAL_MACHINE, szPowerCfgSubKey, 0, KEY_READ, &hKey);
406 if (Ret != ERROR_SUCCESS)
407 {
408 TRACE("RegOpenKeyEx failed: %d\n", Ret);
409 TRACE("Using defaults: 3600, 3\n");
410 *RangeMax = 3600;
411 *RangeMin = 3;
412 ReleaseSemaphore(PPRegSemaphore, 1, NULL);
413 return TRUE;
414 }
415
416 Ret = RegQueryValueExW(hKey, szDiskMax, 0, 0, lpValue, &cbValue);
417 if (Ret != ERROR_SUCCESS)
418 {
419 TRACE("Couldn't open DiskSpinDownMax: %d\n", Ret);
420 TRACE("Using default: 3600\n");
421 *RangeMax = 3600;
422 }
423 else
424 {
425 *RangeMax = _wtoi((LPCWSTR)lpValue);
426 }
427
428 cbValue = sizeof(lpValue);
429
430 Ret = RegQueryValueExW(hKey, szDiskMin, 0, 0, lpValue, &cbValue);
431 if (Ret != ERROR_SUCCESS)
432 {
433 TRACE("Couldn't open DiskSpinDownMin: %d\n", Ret);
434 TRACE("Using default: 3\n");
435 *RangeMin = 3;
436 }
437 else
438 {
439 *RangeMin = _wtoi((LPCWSTR)lpValue);
440 }
441
442 RegCloseKey(hKey);
443
444 ReleaseSemaphore(PPRegSemaphore, 1, NULL);
445 SetLastError(ERROR_SUCCESS);
446
447 return TRUE;
448 }
449
450
451 BOOLEAN WINAPI
452 IsAdminOverrideActive(PADMINISTRATOR_POWER_POLICY p)
453 {
454 FIXME("( %p) stub!\n", p);
455 return FALSE;
456 }
457
458
459 BOOLEAN WINAPI
460 IsPwrHibernateAllowed(VOID)
461 {
462 SYSTEM_POWER_CAPABILITIES PowerCaps;
463 FIXME("() stub!\n");
464 NtPowerInformation(SystemPowerCapabilities, NULL, 0, &PowerCaps, sizeof(PowerCaps));
465 return FALSE;
466 }
467
468
469 BOOLEAN WINAPI
470 IsPwrShutdownAllowed(VOID)
471 {
472 SYSTEM_POWER_CAPABILITIES PowerCaps;
473 FIXME("() stub!\n");
474 NtPowerInformation(SystemPowerCapabilities, NULL, 0, &PowerCaps, sizeof(PowerCaps));
475 return FALSE;
476 }
477
478
479 BOOLEAN WINAPI
480 IsPwrSuspendAllowed(VOID)
481 {
482 SYSTEM_POWER_CAPABILITIES PowerCaps;
483 FIXME("() stub!\n");
484 NtPowerInformation(SystemPowerCapabilities, NULL, 0, &PowerCaps, sizeof(PowerCaps));
485 return FALSE;
486 }
487
488
489 BOOLEAN WINAPI
490 ReadGlobalPwrPolicy(PGLOBAL_POWER_POLICY pGlobalPowerPolicy)
491 {
492 GLOBAL_MACHINE_POWER_POLICY glMachPwrPolicy;
493 GLOBAL_USER_POWER_POLICY glUserPwrPolicy;
494 HKEY hKey;
495 DWORD dwSize;
496 LONG Err;
497
498 ReleaseSemaphore(PPRegSemaphore, 1, NULL);
499
500 // Getting user global power policy
501 Err = RegOpenKeyW(HKEY_CURRENT_USER, L"Control Panel\\PowerCfg\\GlobalPowerPolicy", &hKey);
502 if (Err != ERROR_SUCCESS)
503 {
504 ERR("RegOpenKeyW failed: %d\n", Err);
505 ReleaseSemaphore(PPRegSemaphore, 1, NULL);
506 SetLastError(Err);
507 return FALSE;
508 }
509
510 dwSize = sizeof(glUserPwrPolicy);
511 Err = RegQueryValueExW(hKey, L"Policies", NULL, NULL, (LPBYTE)&glUserPwrPolicy, &dwSize);
512 if (Err != ERROR_SUCCESS)
513 {
514 ERR("RegQueryValueExW failed: %d\n", Err);
515 ReleaseSemaphore(PPRegSemaphore, 1, NULL);
516 SetLastError(Err);
517 return FALSE;
518 }
519
520 RegCloseKey(hKey);
521
522 // Getting machine global power policy
523 Err = RegOpenKeyW(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Controls Folder\\PowerCfg\\GlobalPowerPolicy", &hKey);
524 if (Err != ERROR_SUCCESS)
525 {
526 ERR("RegOpenKeyW failed: %d\n", Err);
527 ReleaseSemaphore(PPRegSemaphore, 1, NULL);
528 SetLastError(Err);
529 return FALSE;
530 }
531
532 dwSize = sizeof(glMachPwrPolicy);
533 Err = RegQueryValueExW(hKey, L"Policies", NULL, NULL, (LPBYTE)&glMachPwrPolicy, &dwSize);
534 if (Err != ERROR_SUCCESS)
535 {
536 ERR("RegQueryValueExW failed: %d\n", Err);
537 ReleaseSemaphore(PPRegSemaphore, 1, NULL);
538 SetLastError(Err);
539 return FALSE;
540 }
541
542 RegCloseKey(hKey);
543
544 memcpy(&pGlobalPowerPolicy->user, &glUserPwrPolicy, sizeof(GLOBAL_USER_POWER_POLICY));
545 memcpy(&pGlobalPowerPolicy->mach, &glMachPwrPolicy, sizeof(GLOBAL_MACHINE_POWER_POLICY));
546
547 ReleaseSemaphore(PPRegSemaphore, 1, NULL);
548 SetLastError(ERROR_SUCCESS);
549
550 return TRUE;
551 }
552
553
554 BOOLEAN WINAPI
555 ReadProcessorPwrScheme(UINT uiID,
556 PMACHINE_PROCESSOR_POWER_POLICY pMachineProcessorPowerPolicy)
557 {
558 FIXME("(%d, %p) stub!\n", uiID, pMachineProcessorPowerPolicy);
559 SetLastError(ERROR_FILE_NOT_FOUND);
560 return FALSE;
561 }
562
563
564 BOOLEAN WINAPI
565 ReadPwrScheme(UINT uiID,
566 PPOWER_POLICY pPowerPolicy)
567 {
568 USER_POWER_POLICY userPwrPolicy;
569 MACHINE_POWER_POLICY machinePwrPolicy;
570 WCHAR szNum[3 + 1]; // max number - 999
571
572 ReleaseSemaphore(PPRegSemaphore, 1, NULL);
573
574 swprintf(szNum, L"%d", uiID);
575
576 if (!POWRPROF_GetUserPowerPolicy(szNum, &userPwrPolicy, 0, NULL, 0, NULL))
577 {
578 ReleaseSemaphore(PPRegSemaphore, 1, NULL);
579 return FALSE;
580 }
581
582 if (!POWRPROF_GetMachinePowerPolicy(szNum, &machinePwrPolicy))
583 {
584 ReleaseSemaphore(PPRegSemaphore, 1, NULL);
585 return FALSE;
586 }
587
588 memcpy(&pPowerPolicy->user, &userPwrPolicy, sizeof(USER_POWER_POLICY));
589 memcpy(&pPowerPolicy->mach, &machinePwrPolicy, sizeof(MACHINE_POWER_POLICY));
590
591 ReleaseSemaphore(PPRegSemaphore, 1, NULL);
592 SetLastError(ERROR_SUCCESS);
593
594 return TRUE;
595 }
596
597
598 BOOLEAN WINAPI
599 SetActivePwrScheme(UINT uiID,
600 PGLOBAL_POWER_POLICY lpGlobalPowerPolicy,
601 PPOWER_POLICY lpPowerPolicy)
602 {
603 FIXME("(%d, %p, %p) stub!\n", uiID, lpGlobalPowerPolicy, lpPowerPolicy);
604 SetLastError(ERROR_FILE_NOT_FOUND);
605 return FALSE;
606 }
607
608
609 BOOLEAN WINAPI
610 SetSuspendState(BOOLEAN Hibernate,
611 BOOLEAN ForceCritical,
612 BOOLEAN DisableWakeEvent)
613 {
614 FIXME("(%d, %d, %d) stub!\n", Hibernate, ForceCritical, DisableWakeEvent);
615 return TRUE;
616 }
617
618
619 BOOLEAN WINAPI
620 WriteGlobalPwrPolicy(PGLOBAL_POWER_POLICY pGlobalPowerPolicy)
621 {
622 HKEY hKey;
623 GLOBAL_USER_POWER_POLICY gupp;
624 GLOBAL_MACHINE_POWER_POLICY gmpp;
625
626 gupp = pGlobalPowerPolicy->user;
627 gmpp = pGlobalPowerPolicy->mach;
628
629 if (RegOpenKeyEx(HKEY_CURRENT_USER,
630 L"Control Panel\\PowerCfg\\GlobalPowerPolicy",
631 0,
632 KEY_ALL_ACCESS,
633 &hKey))
634 return FALSE;
635
636 if (RegSetValueExW(hKey,szPolicies,(DWORD)NULL,REG_BINARY,(const unsigned char *)&gupp,sizeof(GLOBAL_USER_POWER_POLICY)) == ERROR_SUCCESS)
637 {
638 RegCloseKey(hKey);
639
640 if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,
641 L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Controls Folder\\PowerCfg\\GlobalPowerPolicy",
642 0,
643 KEY_ALL_ACCESS,
644 &hKey))
645 return FALSE;
646
647 if (RegSetValueExW(hKey,szPolicies,(DWORD)NULL,REG_BINARY,(const unsigned char *)&gmpp,sizeof(GLOBAL_MACHINE_POWER_POLICY)) == ERROR_SUCCESS)
648 {
649 RegCloseKey(hKey);
650 return TRUE;
651 }
652 else
653 {
654 return FALSE;
655 }
656 }
657 else
658 {
659 RegCloseKey(hKey);
660 return FALSE;
661 }
662 }
663
664
665 BOOLEAN WINAPI
666 WriteProcessorPwrScheme(UINT ID,
667 PMACHINE_PROCESSOR_POWER_POLICY pMachineProcessorPowerPolicy)
668 {
669 FIXME("(%d, %p) stub!\n", ID, pMachineProcessorPowerPolicy);
670 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
671 return FALSE;
672 }
673
674
675 BOOLEAN WINAPI
676 WritePwrScheme(PUINT puiID,
677 LPWSTR lpszName,
678 LPWSTR lpszDescription,
679 PPOWER_POLICY pPowerPolicy)
680 {
681 FIXME("(%p, %s, %s, %p) stub!\n", puiID, debugstr_w(lpszName), debugstr_w(lpszDescription), pPowerPolicy);
682 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
683 return FALSE;
684 }
685
686
687 BOOLEAN WINAPI
688 ValidatePowerPolicies(PGLOBAL_POWER_POLICY pGPP, PPOWER_POLICY pPP)
689 {
690 GLOBAL_POWER_POLICY pGlobalPowerPolicy;
691 POWER_POLICY pPowerPolicy;
692
693 FIXME("(%p, %p) not fully implemented\n", pGPP, pPP);
694
695 if (!GetCurrentPowerPolicies(&pGlobalPowerPolicy, &pPowerPolicy))
696 {
697 ERR("GetCurrentPowerPolicies(%p, %p) failed\n", pGPP, pPP);
698 return FALSE;
699 }
700
701 if (pGPP)
702 {
703 //memcpy(&pGPP, &pGlobalPowerPolicy, sizeof(GLOBAL_POWER_POLICY));
704 }
705
706 if (pPP)
707 {
708 //memcpy(&pPP, &pPowerPolicy, sizeof(POWER_POLICY));
709 }
710
711 SetLastError(ERROR_SUCCESS);
712 return TRUE;
713 }
714
715 BOOL WINAPI
716 DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
717 {
718 FIXME("(%p, %d, %p) not fully implemented\n", hinstDLL, fdwReason, lpvReserved);
719
720 switch(fdwReason)
721 {
722 case DLL_PROCESS_ATTACH:
723 {
724
725 HKEY hKey;
726 LONG r;
727
728 DisableThreadLibraryCalls(hinstDLL);
729
730 r = RegOpenKeyExW(HKEY_LOCAL_MACHINE, szPowerCfgSubKey, 0, KEY_READ | KEY_WRITE, &hKey);
731
732 if (r != ERROR_SUCCESS)
733 {
734 TRACE("Couldn't open registry key HKLM\\%s, using some sane(?) defaults\n", debugstr_w(szPowerCfgSubKey));
735 }
736 else
737 {
738 BYTE lpValue[40];
739 DWORD cbValue = sizeof(lpValue);
740 r = RegQueryValueExW(hKey, szLastID, 0, 0, lpValue, &cbValue);
741 if (r != ERROR_SUCCESS)
742 {
743 TRACE("Couldn't open registry entry HKLM\\%s\\LastID, using some sane(?) defaults\n", debugstr_w(szPowerCfgSubKey));
744 }
745 RegCloseKey(hKey);
746 }
747
748 PPRegSemaphore = CreateSemaphoreW(NULL, 1, 1, szSemaphoreName);
749 if (PPRegSemaphore == NULL)
750 {
751 ERR("Couldn't create Semaphore: %d\n", GetLastError());
752 return FALSE;
753 }
754 break;
755 }
756 case DLL_PROCESS_DETACH:
757 CloseHandle(PPRegSemaphore);
758 break;
759 }
760 return TRUE;
761 }