On the official Microsoft documentation the function RegSetValueEx
of the Windows API is defined as follows:
LONG WINAPI RegSetValueEx(
_In_ HKEY hKey,
_In_opt_ LPCTSTR lpValueName,
_Reserved_ DWORD Reserved,
_In_ DWORD dwType,
_In_ const BYTE *lpData,
_In_ DWORD cbData
);
As you can see, the value *lpData
, created to store the data of the value, is defined as a const BYTE
, which is declared in WinDef.h
as unsigned char
.
Here are my definitions:
//Variables needed for registry value creation.
PTCHAR regValueName = TEXT("dwValue");
DWORD regValueType = REG_DWORD;
BYTE regData = 1;
const BYTE *pRegData = ®Data;
DWORD dataSize = sizeof(regData);
This is how I am calling the RegSetValueEx function:
setValueKey = RegSetValueEx(*pHandleResult, regValueName, reserved,
regValueType, pRegData, dataSize);
The *pHandleResult
is a HANDLE
returned by RegOpenKeyEx
, but I am not displaying that code here so as not to make the code too long.
I want to create a DWORD value with content of 1, and the function creates it, but the content ends up being this text:
«Invalid (DWORD 32 bit) value»
I know that I can define the regData
as a DWORD
, assign 1 and that would work, but I want to know basically why it does not work for me using the data that is declared by the official Microsoft documentation. What am I doing wrong?
I appreciate the help. If you need any other information, I will gladly give it.