The biggest error is in (const BYTE*)0x00
: you are casting 0x00 to a BYTE *
, which means that basically you are passing a NULL
pointer. Instead, you should create a DWORD
variable, put the value you want to store in the registry in it and pass a pointer to it instead of that 0x00
.
Also, you must change REG_SZ
to REG_DWORD
if you want to store a DWORD
value, otherwise the DWORD
will be interpreted as a (somewhat strange) string.
RegOpenKeyEx(HKEY_CURRENT_USER, "Software\pager", 0, KEY_ALL_ACCESS, &hKey);
DWORD value=0;
RegSetValueEx(hKey, TEXT("Save"), 0, REG_DWORD, (const BYTE*)&value, sizeof(value));
RegCloseKey(hKey);
But, most importantly, you should really check the return values of these functions: now you're just "hoping" they work, ignoring any failure and continuing with the instruction flow, which can lead to unexpected situations.
If you checked the error codes you would have noticed immediately that it is the RegSetValueEx
function that fails, and the error code may have been something like "invalid parameter", that would have pointed you in the right direction.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…