c++ - RegKeyValue 返回无意义的数据

标签 c++ winapi

char value[255];
DWORD BufferSize = 8192;

RegGetValue(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", L"ProductName", RRF_RT_ANY, NULL, &value, &BufferSize);

cout << value;

RegKeyValue() 运行后,看起来值是

    value   0x0034f50c "ÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌ...  char[255]

这是怎么回事?

注意:RegKeyValue() 返回 0

最佳答案

这里有两个问题。

  1. 确保返回值RegGetValueERROR_SUCCESS。如果不是,例程失败。此外,您还可以查看写入到 BufferSize 中的内容,因为 RegGetValue 指定写入的字节数。

  2. 您传入定义为 char value[255]; 的缓冲区,然后将其长度指定为 8192。这可能会导致缓冲区溢出。

关于c++ - RegKeyValue 返回无意义的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14430256/

相关文章:

c++ - 如何用OpenCV绘制圆角矩形(带圆角的矩形)?

c++ - 从 C++ 队列中间删除一个节点

c++ - Vector 类(数组)上的迭代器

c++ - _wfreopen 适用于 c :/path/file. txt 但不适用于 c :\path\file. txt?

c++ - DoModal返回-1 Getlasterror说无效的句柄

c++ - 来自不同线程的同步输出流

python - 需要一种使用 Python 从 Zune 和 Windows Media Player 中检索当前播放歌曲的方法

c# 从任务栏中删除第 3 方应用程序

c - 鼠标悬停在选项卡项上的通知代码

C++ concat const char 与来自#define 的值