RegSetValueEx question

Hi. I have this code
1
2
3
BYTE bShow = 1;
DWORD size = sizeof(BYTE);
RegSetValueEx(hKey, TEXT("ToolBar"), 0, REG_DWORD, (const BYTE*)&bShow, &size);


When I check in the registry on the Data column it says (invalid DWORD value).
The name ToolBar shows correctly in the Name column and it says REG_DWORD in the Type column but in the Data column it says (invalid DWORD value)
How can I fix this?
Last edited on
The last parameter should be the size of the data being stored, not a pointer to the size.

RegSetValueEx(hKey, TEXT("ToolBar"), 0, REG_DWORD, (const BYTE*)&bShow, sizeof DWORD);
Last edited on
That worked but now the value says 0x004d2201(5054977). bShow is only 1 byte long and maximum value a byte can hold is 255. Should I cast bShow to DWORD before I pass it to RegSetValueEx?
Ah whoops, replace sizeof DWORD with sizeof bShow.
Now I have same problem like in the beginning. In my original post i meant to write
 
RegSetValueEx(hKey, TEXT("ToolBar"), 0, REG_DWORD, (const BYTE*)&bShow, size);

But by mistake I wrote &size for the last parameter. I think the last parameter should always be sizeof(DWORD) if the fourth parameter is REG_DWORD
Topic archived. No new replies allowed.