AlexandruC
AlexandruC

Reputation: 3637

c++ registry not getting second value

why is this not working? the first RegGetValue puts correct values in value variable, the second doesn't, however if I comment the first RegGetValue the second will then work and put the correct content into value2 variable. I tried closind and reopening the registry key using RegOpenKeyEx after the first RegGetValue function call but with no succes. What I am doing wrong

HKEY hKey = NULL;
LSTATUS res;

res=RegOpenKeyEx(HKEY_CLASSES_ROOT, "", 0, KEY_READ|KEY_WOW64_64KEY, &hKey);
if(res!=ERROR_SUCCESS)
         printf("insucces\n");
else {
    char value[255], value2[255];
    memset(value,0,255);
    memset(value2,0,255);
DWORD BufferSize = BUFFER;
RegGetValue(hKey,"\\.jpeg","",RRF_RT_ANY,NULL,(PVOID)&value, &BufferSize);
strcat(value,"\\DefaultIcon");
RegGetValue(hKey,"jpegfile\\DefaultIcon","",RRF_RT_ANY,NULL,(PVOID)&value2, &BufferSize);

printf("succes %s\n",value2);

}

Upvotes: 0

Views: 109

Answers (1)

Joachim Isaksson
Joachim Isaksson

Reputation: 181047

From the RegGetValue manual about your last parameter;

pcbData [in, out, optional]

A pointer to a variable that specifies the size of the buffer pointed to by the pvData parameter, in bytes. When the function returns, this variable contains the size of the data copied to pvData.

In other words, the contents of your BufferSize variable is changed by the first call to be the size of the first value returned, and needs to be reset before the second call.

Upvotes: 4

Related Questions