Re: registry code sample

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



On Sun, 25 Jan 2009 18:41:55 +0100, "Starglider 4 \(Marco Knoester\)" <x@xxxxxx>
wrote:

You don't seem to need two steps and can probably start with

DWORD dwDisp;
HKEY hKeyCompany;
if ( RegCreateKey(HKEY_CURRENT_USER, "Software\\company",
0, NULL, 0, KEY_ALL_ACCESS, NULL, &hKeyCompany, &dwDisp) ) ...

I used NULL for lpSecurityAttributes. do you really need to make the handle
inheritable?

LPDWORD disp;

if(RegCreateKeyEx(ihkey[0],subkey,0,NULL,options,rsam,sa,iphkey[1],disp)!=ERROR_SUCCESS)_er=1;

What does "disp" point to? (Answer: nothing) You've done that more than once.
And it will cause an error. Declaring a pointer does not automatically make it
point to anything. There's no real need for the pointer itself. Just use
"DWORD dwDisp" and specify its location (&dwDisp, as above).

***********************

const BYTE* data;
BYTE d=0;

Something is fishy here. You have **one** byte of data ...

data=&d;
DWORD size=sizeof(DWORD);
if(RegSetValueEx(ihkey[1],value_name,0,REG_DWORD,data,size)!=ERROR_SUCCESS)_er=1;

.... but you tell RSVEx() to read (from the location data) **four** bytes.

How about,

DWORD dwData = 0; // or whatever value you want in the registry

if(RegSetValueEx(hKeyCompany,"val1",0,REG_DWORD,&dwData,sizeof(DWORD)) ...

dwData = 0; // or whatever value you want in the registry

if(RegSetValueEx(hKeyCompany,"val2",0,REG_DWORD,&dwData,sizeof(DWORD)) ...
--
- Vince
.