RegSetValueEx inputting incorrect data into Registry

The issue I'm having is that my application is inputting the incorrect data into the registry (instead of a file path, it inputs characters such as "㩃啜敳獲啜敳屲灁") and I don't know what the issue is, the relevant source code is below (Includes, etc have been removed).

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);

Any help will be appreciated.

Answers


RegSetValueEx expects (for REG_SZ) that the data you're passing in is Unicode, unless you're not defining UNICODE in your environment. But .c_str is likely a non-Unicode stream.


Need Your Help

Select most recent records by DB2 date in form of YYYYMMDD

sql db2

I am importing records from a DB2 data source into a MS SQL Server destination.

how to get all the permissions on facebook

iphone objective-c facebook-ios-sdk

in some applications, I see "Access my data any time" when I give the permissions to the iphone application, how can i do that with facebook-ios-sdk ?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.