Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Enterprise
Expertise: Beginner
Sep 12, 2002

How to Read a Value from a Registry?


You can read a key from a particular path in registry by using the RegQueryValueEx function. The following piece of code reads a particular key under HKEY_LOCAL_MACHINE\Software\Devx:
 
void GetKeyValue(char *key, char *retStr, int
                                        *retCode)
{
  HKEY keyVal;
  long errorCode;
  char value[500];
  DWORD size, type;
  *retCode = 0;
  strcpy(retStr, "");

  errorCode = RegOpenKeyEx( HKEY_LOCAL_MACHINE
      , "Software\\Devx", 0, KEY_READ,&keyVal);

  if(errorCode==0)
  {
     size = sizeof(value) - 1;
     type = REG_SZ;
     errorCode = RegQueryValueEx(keyVal, key, 0,
             &type,(unsigned char *)value, &size);
     if(errorCode==0)
     {
        strcpy(retStr, value);
     }else
        *retCode = -1;

     RegCloseKey(keyVal);
  }else
     *retCode = -1;
}
Amit Vij
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date