gpt4 book ai didi

c++ - RegSetValueEx 将不正确的数据输入注册表

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:30:52 25 4
gpt4 key购买 nike

我遇到的问题是我的应用程序将不正确的数据输入到注册表中(而不是文件路径,它输入了诸如“㩃喝法获得喝法屲灁”之类的字符)而且我不知道问题是什么,下面是相关的源代码(包括等已被删除)。

stringstream ss;

char* file_path = getenv("APPDATA");
strcat(file_path, "\\Application.exe");
ss << file_path;
ss >> file_path_string;
CA2W unicodeFile_path(file_path);
cout << "Downloading File";
HRESULT hr = URLDownloadToFile ( NULL, _T("http://example.com/application.exe"), unicodeFile_path, 0, NULL );
cout << "Done" << endl;
cout << "Adding to registry" << endl;
HKEY hKey;
CA2W registryLocation("Software\\Microsoft\\Windows\\CurrentVersion\\Run");
CA2W registryKey("Application");
// Check registry if exists, otherwise create.
RegCreateKeyEx(HKEY_CURRENT_USER,
registryLocation,
0,
NULL,
REG_OPTION_NON_VOLATILE,
KEY_WRITE,
NULL,
&hk,
&dwDisp);
// Store reg value
RegSetValueEx(hk,
registryKey,
NULL,
REG_SZ,
(const BYTE*)file_path_string.c_str(),
file_path_string.size() + 1);

我们将不胜感激。

最佳答案

RegSetValueEx 期望(对于 REG_SZ)您传入的数据是 Unicode,除非您没有在您的环境中定义 UNICODE。但是 .c_str 可能是非 Unicode 流。

关于c++ - RegSetValueEx 将不正确的数据输入注册表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12358245/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com