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);
}
From the RegGetValue manual about your last parameter;
In other words, the contents of your
BufferSizevariable is changed by the first call to be the size of the first value returned, and needs to be reset before the second call.