I am working on the code in wherin i have to get the data under the particular regitry path..For this i m using the fnctions to open the key and subkey as
RegOpenKeyEx (HKEY_LOCAL_MACHINE, sk, NULL, KEY_READ, &hKey);
which on debugging giving me unused value handle to the path i need to access.
What is going wrong here ? can anybody tell me ?
void GetAlgorithmList()
{
HKEY hKey=0;
LPCTSTR sk = TEXT("SOFTWARE\\ALGORITHM");
LONG openRes=RegOpenKeyEx (HKEY_LOCAL_MACHINE,sk,NULL,KEY_READ ,&hKey);
long lret;
PVALENT val_list=0;
unsigned long totalsize = 1000;
lret = 0;
LPWSTR szValueBuf=NULL;
lret = RegQueryMultipleValues(hKey,val_list,totalsize,szValueBuf,&totalsize);
if (lret == ERROR_SUCCESS)
{
printf("Success 1");
}
FILE* pFile = fopen("D:\\HinalH\\logFile.txt", "a+");
fopen("D:\\logFile.txt", "a+");
fprintf(pFile, "%d\n",szValueBuf);
fclose(pFile);
RegCloseKey(hKey);
}
Thanks in advance
First: You should check the result of
RegOpenKeyEx. Please read the documentation more carefully. Its really necessary to handle errors if they occur at runtime.Second: Please take a look to the documentation for function RegQueryMultipleValues.
Just take your attention to the
val_listparameter and to thelpValueBufparameter both are out parameter. I cannot see that you handle them in the right way in your code.Third: I cannot find any sample using RegQueryMultipleValues in the web. I played a little arround and created a working example.
Here is the sample I did.
To be honest for me it seems this function is not the best option to access information in the registry. Better you should use functions like RegQueryValueEx.