Windows API operating experience and summary of the registry _ registration Form

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.