registry code sample
- From: "Starglider 4 \(Marco Knoester\)" <rebel-6-out@xxxxxxxxx>
- Date: Sat, 24 Jan 2009 23:45:13 +0100
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
.
- Follow-Ups:
- Re: registry code sample
- From: Norman Bullen
- Re: registry code sample
- Prev by Date: Re: Crash of an app
- Next by Date: Re: Struggling with bugs in modeless dialogs in VC++ 2.0
- Previous by thread: Crash of an app
- Next by thread: Re: registry code sample
- Index(es):