C++ RegSetValueEx将不正确的数据输入注册表
我遇到的问题是,我的应用程序正在将不正确的数据输入注册表(而不是文件路径,它输入字符,例如“㩃啜敳獲啜敳屲灁") 我不知道问题是什么,下面是相关的源代码(包括等已删除)C++ RegSetValueEx将不正确的数据输入注册表,c++,visual-studio,registry,C++,Visual Studio,Registry,我遇到的问题是,我的应用程序正在将不正确的数据输入注册表(而不是文件路径,它输入字符,例如“㩃啜敳獲啜敳屲灁") 我不知道问题是什么,下面是相关的源代码(包括等已删除) stringstreamss; char*file_path=getenv(“APPDATA”); strcat(文件路径“\\Application.exe”); ss>文件路径字符串; CA2W文件路径(文件路径); coutRegSetValueEx(对于REG_SZ)期望您传入的数据是Unicode,除非您在环境中没有定
stringstreamss;
char*file_path=getenv(“APPDATA”);
strcat(文件路径“\\Application.exe”);
ss>文件路径字符串;
CA2W文件路径(文件路径);
coutRegSetValueEx(对于REG_SZ)期望您传入的数据是Unicode,除非您在环境中没有定义Unicode。但是.c_str可能是非Unicode流。您有正确的方法吗?
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);