You need to pass the address of value
:
iResult = RegSetValueEx(hKey,
L"Test",
NULL,
REG_DWORD,
(const BYTE*)&value, // Change made here.
sizeof(value));
The error code 998
means:
Invalid access to memory location.
When the address of value
is not passed its actual value (3
) is being used as a memory address, causing the failure.