Reading functions commonly used in the registry
RegOpenKeyEx is used to open a key
RegSetValueEx is used to set the key value of a key
RegQueryValueEx the value used to read a key
RegCloseKey is used to turn off Regopen open keys
RegQueryValueEx usually uses two times to read the key value, read only the key size for the first time, then allocate the memory, and then use the RegQueryValueEx to read the key value to the buffer.
Here is an example of reading the path key value under Windows
HKEY HK; int result = RegOpenKeyEx (HKEY_LOCAL_MACHINE, _t ("System\\controlset001\\control\\session manager\\environm
Ent "), NULL, Key_read, &HK); If (result!= error_success) {if (result = = Error_file_not_found) {MessageBox (g.hwnd,_t ("No such key in
RegOpenKeyEx "), _t (" title "), mb_iconwarning);
else return;
} DWORD lsize;
result = RegQueryValueEx (HK, _t ("Path"), Null,null, NULL, &lsize); If (result!= error_success) {if (result = = Error_file_not_found) {MessageBox (g.hwnd,_t ("No such key in
RegQueryValue "), _t (" title "), mb_iconwarning);
else if (result = = Error_more_data) {MessageBox (g.hwnd,_t ("need more Buffer"), _t ("title"), mb_iconwarning);
else return;
} TCHAR *value = (TCHAR *) malloc (lsize * sizeof (TCHAR)); result = RegQueryValueEx (HK, _t ("Path"), Null,null, (LPBYTE) value, &lsize);
If (result!= error_success) {if (result = = Error_file_not_found) {MessageBox (g.hwnd,_t ("No such key
In RegQueryValue "), _t (" title "), mb_iconwarning);
else if (result = = Error_more_data) {MessageBox (g.hwnd,_t ("need more Buffer"), _t ("title"), mb_iconwarning);
else return;
} setwindowtext (G.hwndedit,value);
Free (value); RegCloseKey (HK);
Novice FAQ
RegSetValueEx runtime failed with return code 5,
Workaround: This situation is due to the lack of access to the registry, the meaning of access denied, so pay attention to see if the permissions are not enough, if you change to
Key_all_access is no problem, such as reading and writing permissions can be.