How to Read a Value from a Registry?

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_MACHINESoftwareDevx:

 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;}
See also  Why ChatGPT Is So Important Today

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist