Benjamin Cutler cutler@cs.colostate.edu writes:
- r = RegOpenKeyExA(HKEY_LOCAL_MACHINE, szPowerCfgSubKey, 0, KEY_READ | KEY_WRITE, &hKey);
- if (r != ERROR_SUCCESS) {
TRACE("RegOpenKeyEx failed: %ld\n", r);
bSuccess = FALSE;
goto end;
- }
- r = RegQueryValueExA(hKey, "LastID", 0, 0, lpValue, &cbValue);
- if (r != ERROR_SUCCESS) {
TRACE("RegQueryValueEx failed: %ld\n", r);
bSuccess = FALSE;
goto end;
- }
- r = RegSetValueExA(hKey, "LastID", 0, REG_SZ, lpValue, strlen(lpValue));
- if (r != ERROR_SUCCESS) {
TRACE("RegSetValueEx failed: %ld\n", r);
bSuccess = FALSE;
If you can open the key for write access it means you have the needed permissions, there's no need to actually try to write a value.
PPRegSemaphore = OpenSemaphoreA(SEMAPHORE_ALL_ACCESS, 0, "PowerProfileRegistrySemaphore");
if (PPRegSemaphore == NULL) {
/* FIXME: The 'default' security attributes are probably not
* correct, but they should work for now */
SECURITY_ATTRIBUTES SecAttributes = { sizeof(SECURITY_ATTRIBUTES), NULL, 0 };
PPRegSemaphore = CreateSemaphoreA(&SecAttributes, 1, 1, "PowerProfileRegistrySemaphore");
CreateSemaphore works fine if the semaphore exists, no need to try an OpenSemaphore first. Also using Unicode functions right away would avoid the need for someone to come back and change them later.