The Registry is a tree structure that can be stored recursively.
Steps:
1. First, customize the structure for storing Registry Information
2. the constructor getregvaluestruct stores key values based on primary keys and subkeys.
3. the constructor getregstruct stores the entire registry structure based on the primary key and subkey.
The specific implementation is as follows:
1. First, customize the structure for storing Registry Information
Custom storage struct <br/> typedef struct _ reg_value_ctrl // struct for storing key values <br/>{< br/> char szvaluename [max_path]; // key value name <br/> char szvalue [max_path]; // key value content <br/> _ reg_value_ctrl * pnext; <br/>} reg_value_ctrl, * preg_value_ctrl; <br/> typedef struct _ reg_info_ctrl // Store complete registry key struct data <br/>{< br/> // registry key value struct <br/> char szkeyname [max_path]; // key name <br/> preg_value_ctrl pregvaluectrl; <br/> // registry key subitem structure <br/>__ reg_info_ctrl * psubkeyctrl [max_sub]; <br/>} reg_info_ctrl, * preg_info_ctrl;
2. the constructor getregvaluestruct stores key values based on primary keys and subkeys.
// Store key item values based on primary keys and subkeys <br/> preg_value_ctrl getregvaluestruct (hkey hmainkey, tchar subkey [max_path]) <br/>{< br/> preg_value_ctrl P, last, head; <br/> tchar temp [max_path]; <br/> hkey = NULL; <br/> tchar STR [max_path] = {0 }; // store the read value <br/> DWORD num = sizeof (STR), Index = 0, RC; <br/> rc = regopenkeyex (hmainkey, subkey, 0, key_all_access, & hkey); <br/> If (rc = error_success) <br/>{< br/> int n = 0; <br/> head = last = NULL; <br/> P = (preg_value_ctrl) malloc (regvaluelen); <br/> // memset (STR, '/0 ', sizeof (tchar) * 260); <br/> memset (STR, 0, sizeof (tchar) * 260 ); <br/> // storage value <br/> while (regenumvalue (hkey, index, STR, & num, null) = 0) <br/> {// traverse the value and process it <br/> // printf ("/T % s/n", STR ); <br/> // zeromemory (& STR [strlen (STR) + 1], MAX_PATH-strlen (STR)-1 ); </P> <p> char * name = wide2short (STR); <br/> strcpy (p-> szvaluename, name ); <br/> // read key value <br/> DWORD keytype; <br/> DWORD dwlength = 20; <br/> tchar Buf [260]; <br/> regqueryvalueex (hkey, STR, 0, & keytype, (byte *) BUF, & dwlength ); <br/> char value [max_path]/* = {0} */; <br/> memset (value, 0, max_path); <br/> sprintf (value, "% s", wide2short (BUF); <br/> strcpy (p-> szvalue, value); <br/> index ++; <br/> num = max_path; <br/> P-> pnext = NULL; <br/> + + N; <br/> If (n = 1) <br/> head = P; <br/> else <br/> last-> pnext = P; <br/> last = P; <br/> P = (preg_value_ctrl) malloc (regvaluelen); <br/>}< br/> free (p); <br/> return head; <br/>}< br/> else <br/> return NULL; <br/>}
3. the constructor getregstruct stores the entire registry structure based on the primary key and subkey.
Getregstruct stores the entire registry structure based on the primary key and subkey <br/> void getregstruct (hkey hmainkey, tchar subkey [max_path], preg_info_ctrl * psubkey_head) <br/>{< br/> preg_info_ctrl subkey_p, subkey_last; <br/> tchar temp [max_path]; <br/> hkey = NULL; <br/> tchar STR [max_path]; // store the read value <br/> DWORD num = sizeof (STR), Index = 0, initial_index = 0, RC; <br/> rc = regopenkeyex (hmainkey, subkey, 0, key_all_access, & hkey); <br/> If (rc = error_success) <br/>{< br/> subkey_p = (preg_info_ctrl) malloc (reginfostructlen); </P> <p> strcpy (subkey_p-> szkeyname, wide2short (subkey )); <br/> subkey_p-> pregvaluectrl = getregvaluestruct (hmainkey, subkey ); // key-value struct <br/> // initialize the sub-key value </P> <p> for (Int J = 0; j <max_sub; j ++) <br/>{< br/> subkey_p-> psubkeyctrl [J] = NULL; <br/>}< br/> while (regenumkeyex (hkey, index, STR, & num, null) = error_success) <br/>{< br/> // recursion after traversing the subitem <br/> wcscpy (temp, subkey); // This is required. Otherwise, exceptions may occur. <br/> wcscat (temp, l "//"); <br/> wcscat (temp, STR); <br/> getregstruct (hmainkey, temp, & (subkey_p-> psubkeyctrl [Index]); // recursion </P> <p> index ++; <br/> num = max_path; </P> <p >}</P> <p> * psubkey_head = subkey_p; <br/>}< br/> else <br/> * psubkey_head = NULL; <br/>}