Recently, you need to manipulate the registry in the program you write. Summarize some experience, and make a demo for later use, now take it out and share with you ...
For ease of use, some operations are written as functions to facilitate invocation, as shown in the following code:
I. Definition
HKEY hkey;
Char content[256]; The contents of the queried registry key value
DWORD DWTYPE=REG_SZ; Define read data type
DWORD dwlength=256;
struct Hkey__*rootkey; Registry primary Key Name
TCHAR *subkey; To open the address of the registry key
TCHAR *keyname; Want to set the name of the item
TCHAR *valuename; Want to set the name of the value
lpbyte setcontent_s; String type
int setcontent_d[256]; DWORD type
BYTE setcontent_b[256]; Binary type
int showcontent (struct Hkey__*rerootkey,tchar *resubkey,tchar *revaluename);
int setvalue_s (struct Hkey__*rerootkey,tchar *resubkey,tchar *revaluename,lpbyte resetcontent_s);
int setvalue_d (struct Hkey__*rerootkey,tchar *resubkey,tchar *revaluename,int resetcontent_d[256]);
int Setvalue_b (struct Hkey__*rerootkey,tchar *resubkey,tchar *revaluename,byte resetcontent_b[256]);
int DeleteKey (struct Hkey__*rerootkey,tchar *resubkey,tchar *rekeyname);
int DeleteValue (struct Hkey__*rerootkey,tchar *resubkey,tchar *revaluename);
Second, view functions
Showcontent (struct Hkey__*rerootkey,tchar *resubkey,tchar *revaluename)
{
int i=0; Operation Result: 0==succeed
if (RegOpenKeyEx (Rerootkey,resubkey,0,key_read,&hkey) ==error_success)
{
if ( RegQueryValueEx (Hkey,revaluename,null,&dwtype, (unsigned char *) content,&dwlength)!=error_success)
{
AfxMessageBox ("Error: Unable to inquire about registry information");
I=1;
}
RegCloseKey (hkey);
}
else
{
AfxMessageBox ("Error: Unable to open related hkey");
I=1;
}
return i;
}
Three, set string value function
setvalue_s (struct Hkey__*rerootkey,tchar *resubkey,tchar *revaluename,lpbyte resetcontent_s)
{
int i=0; Operation Result: 0==succeed
//int strlength;
Strlength=cstring (setcontent_s). GetLength ();
if (RegOpenKeyEx (Rerootkey,resubkey,0,key_write,&hkey) ==error_success)
{
if (RegSetValueEx HKey, Revaluename,null,reg_sz,resetcontent_s,cstring (setcontent_s). GetLength ())!=error_success)
{
AfxMessageBox ("Error: Unable to set relevant registry information");
I=1;
}
RegCloseKey (hkey);
}
else
{
AfxMessageBox ("Error: Unable to inquire about registry information");
I=1;
}
return i;
}