registry code sample

Tech-Archive recommends: Fix windows errors by optimizing your registry



Hi,

Here is some registry encoding sample code.
(only a sample of my actual solution.)
Please tell me if everything is basically correct, because
it's my first registry codeing attempt,
and i don't want to mess up my registry.
i've studied msdn very good and checked
everyhing a couple of times. but i haven't yet actually
executed the code in real-time.

Here is the code:

int _er=0,used_keys=2;

HKEY ihkey[2];
PHKEY iphkey[2];

LPCTSTR subkey="SOFTWARE";
REGSAM rsam=KEY_ALL_ACCESS;
if(RegOpenKeyEx(HKEY_CURRENT_USER,subkey,0,rsam,iphkey[0])!=ERROR_SUCCESS)_er=1; ihkey[0]=*iphkey[0]; subkey="company"; DWORD options=REG_OPTION_NON_VOLATILE; LPSECURITY_ATTRIBUTES sa; sa->nLength=sizeof(SECURITY_ATTRIBUTES);//0 sa->lpSecurityDescriptor=NULL; sa->bInheritHandle=TRUE;//true LPDWORD disp; if(RegCreateKeyEx(ihkey[0],subkey,0,NULL,options,rsam,sa,iphkey[1],disp)!=ERROR_SUCCESS)_er=1; if(*disp==REG_CREATED_NEW_KEY) { //int_values ihkey[1]=*iphkey[1]; LPCTSTR value_name="val1"; const BYTE* data; BYTE d=0; data=&d; DWORD size=sizeof(DWORD); if(RegSetValueEx(ihkey[1],value_name,0,REG_DWORD,data,size)!=ERROR_SUCCESS)_er=1; _registered=0; value_name="val2"; d=0; data=&d; size=sizeof(DWORD); if(RegSetValueEx(ihkey[1],value_name,0,REG_DWORD,data,size)!=ERROR_SUCCESS)_er=1; } assert(_er=0); for(int i=0;i<used_keys;i++)RegCloseKey(ihkey[i]);Regards,M

.