简体   繁体   English

C ++注册表没有第二价值

[英]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. 第一个RegGetValue将正确的值放在value变量中,第二个不正确,但是如果我注释第一个RegGetValue,则第二个将工作并将正确的内容放入value2变量中。 I tried closind and reopening the registry key using RegOpenKeyEx after the first RegGetValue function call but with no succes. 我尝试了closind,并在第一次RegGetValue函数调用之后使用RegOpenKeyEx重新打开了注册表项,但是没有成功。 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; RegGetValue手册中获取有关最后一个参数的信息;

pcbData [in, out, optional] pcbData [输入,输出,可选]

A pointer to a variable that specifies the size of the buffer pointed to by the pvData parameter, in bytes. 指向变量的指针,该变量指定pvData参数指向的缓冲区的大小(以字节为单位)。 When the function returns, this variable contains the size of the data copied to pvData. 函数返回时,此变量包含复制到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. 换句话说,第一个调用将BufferSize变量的内容更改为返回的第一个值的大小,并且需要在第二个调用之前将其重置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM