devxlogo

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;}

devx-admin

Share the Post: