如何读取 C++ 中的 REG_NONE 值?
我想用 C++ 从 regedit 读取 REG_NONE 值。
这是我的代码:
#include <iostream>
#include <windows.h>
using namespace std;
//--- Değişkenler ---//
//DWORD
DWORD dw_Rn_Boyut = MAX_PATH;
DWORD dw_Rn_Deger;
DWORD dw_Rn_DegerTipi = REG_NONE;
//HKEY
HKEY hkey_Rn;
//LONG
LONG long_Rn_Sonuc;
int main()
{
long_Rn_Sonuc = RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\DownloadManager\\FoldersTree\\Compressed", 0, KEY_READ | KEY_WOW64_64KEY, &hkey_Rn);
if(long_Rn_Sonuc == ERROR_SUCCESS)
{
long_Rn_Sonuc = RegQueryValueEx(hkey_Rn, "pathW", 0, &dw_Rn_DegerTipi, (LPBYTE)&dw_Rn_Deger, &dw_Rn_Boyut);
if(long_Rn_Sonuc == ERROR_SUCCESS)
{
cout << dw_Rn_Deger;
}
}
getchar();
return 0;
}
我的应用程序显示 3801156
结果。该值是该寄存器值的十进制版本。它等于 3A 00 44
这是我想读取的 reg 值:
但是为什么我的应用程序不读取其他十六进制值?
我该如何解决我的问题?
I want to read REG_NONE value from regedit with C++.
Here are my codes:
#include <iostream>
#include <windows.h>
using namespace std;
//--- Değişkenler ---//
//DWORD
DWORD dw_Rn_Boyut = MAX_PATH;
DWORD dw_Rn_Deger;
DWORD dw_Rn_DegerTipi = REG_NONE;
//HKEY
HKEY hkey_Rn;
//LONG
LONG long_Rn_Sonuc;
int main()
{
long_Rn_Sonuc = RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\DownloadManager\\FoldersTree\\Compressed", 0, KEY_READ | KEY_WOW64_64KEY, &hkey_Rn);
if(long_Rn_Sonuc == ERROR_SUCCESS)
{
long_Rn_Sonuc = RegQueryValueEx(hkey_Rn, "pathW", 0, &dw_Rn_DegerTipi, (LPBYTE)&dw_Rn_Deger, &dw_Rn_Boyut);
if(long_Rn_Sonuc == ERROR_SUCCESS)
{
cout << dw_Rn_Deger;
}
}
getchar();
return 0;
}
My app shows 3801156
as result. This value is decimal version of that reg value. It equals to 3A 00 44
Here is the reg value which I want to read:
But why does not my app read other hex values?
How can I fix my problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不存在
REG_NONE
值这样的东西。成功后,您的dw_Rn_DegerTipi
变量将使用实际值类型(在本例中为REG_BINARY
)进行更新,并且您的dw_Rn_Boyut< /code> 变量将根据读取的实际字节数进行更新。
您的问题是您为
dw_Rn_Dege
变量使用了错误的数据类型。相关数据不是一个 DWORD 值,而是一个 WCHAR 字符串,因此您需要一个 WCHAR 字符缓冲区来接收它。您告诉RegQueryValueEx()
您分配了一个缓冲区来保存MAX_PATH
字节,但实际上没有。因此,当RegQueryValueEx()
尝试向dw_Rn_Deger
的内存地址写入超过 4 个字节时,您的代码中会出现缓冲区溢出错误。试试这个:
There is no such thing as a
REG_NONE
value. On success, yourdw_Rn_DegerTipi
variable will be updated with the actual value type (in this case,REG_BINARY
), and yourdw_Rn_Boyut
variable will be updated with the number of actual bytes read.Your problem is that you are using the wrong data type for your
dw_Rn_Dege
variable. The data in question is not aDWORD
value, it is aWCHAR
character string, so you need aWCHAR
character buffer to receive it. You are tellingRegQueryValueEx()
that you allocated a buffer to holdMAX_PATH
bytes, but you really didn't. So you have a buffer overflow error in your code whenRegQueryValueEx()
tries to write more than 4 bytes to the memory address ofdw_Rn_Deger
.Try this instead: