Not quite.
lpData is a pointer to the data that you want to write to that value, and cdData is the size of that data.
In this case, you want to write a DWORD, which are always 32-bits long, so as cbData, you'll just pass a 4, but, in case the size of DWORD ever changed, for whatever reason, you'll pass size, instead, which you already have from the previous example I gave you a few posts ago.
Now, let's suppose you've written the new port number in the variable port. You pass a pointer to port, casted to a 'BYTE *'.
The resulting line would be:
1 2 3 4 5 6 7 8
|
RegSetValueEx(
hKey,
TEXT("PortNumber"), //This was right, but it's better to add the TEXT macro.
0, //OK
REG_DWORD, // OK
(BYTE*)&port,
size //This had been set to sizeof(DWORD), remember?
);
|
The TEXT macro:
Some compilers define UNICODE by default, so if you were to pass the string literal just like that, you'd get a compiler error (wchar_t string literals are written L"like this", with an upper case L at the beginning).
I forgot to mention this before. Add it to the previous API calls.