C++RegSetValueEx出现问题
C++ RegSetValueEx is giving problems
本文关键字:问题 C++RegSetValueEx 更新时间:2023-10-16
我正在使用RegSetValueEx
设置注册表项。问题是它只写前两个字符。我可以使用RegSetValueExA
(ANSI版本),但我的项目在属性中设置为Unicode,所以我想使用RegSetValueEx
或RegSetValueExW
。
#include <iostream>
#include <Windows.h>
HKEY hKey;
int main()
{
RegCreateKeyEx(HKEY_CURRENT_USER, L"SOFTWARE\stuff", 0, NULL, NULL, KEY_ALL_ACCESS, NULL, &hKey, NULL);
RegSetValueEx(hKey, L"Test", 0, REG_SZ, (const BYTE*)L"test", strlen("test"));
system("PAUSE");
return 0;
}
注册表中的输出是"te"
而不是"test"
。
RegSetValueEx
的最后一个参数必须是值的字节大小,包括终止的null。您给出的长度以字符为单位(每个字符需要两个字节),而不包括null。
我认为sizeof(L"test")
会起作用,或者你可以使用(strlen("test")+1) * sizeof(wchar_t)
请参阅https://msdn.microsoft.com/en-us/library/windows/desktop/ms724923(v=vs.85).aspx
相关文章:
- 警告处理为错误这里有什么问题
- 最小硬币更换问题(自上而下方法)
- 为"adjacent"变量赋值时出现问题
- 我的神经网络不起作用 [XOR 问题]
- 在Ubuntu 16.04上安装Cilk时出现问题
- C++我的数学有什么问题,为什么我的代码不能正确循环
- 编译包含字符串的代码时遇到问题
- Project Euler问题4的错误解决方案
- 问题:什么是QAbstractItemView::NoEditTriggers的反面
- 在编译C++代码(具有dlib和opencv)到WASM时面临问题
- 在进程中对同一管道进行读取和写入时C++管道出现问题
- 静态数据成员的问题-修复链接错误会导致编译器错误
- C++ 雷神库 - 使用资源加载器类时出现问题(不命名类型)
- 一个关于在C++中重载布尔运算符的问题
- 首要问题的答案让值班员搞错了
- setlocale的C++土耳其字符串问题
- 如何重构类层次结构以避免菱形问题
- 基于boost的程序的静态链接——zlib问题
- C++格式化输出问题
- 使用mongocxx驱动程序时包含头文件问题