2

私が抱えている問題は、アプリケーションが誤ったデータをレジストリに入力していることです (ファイル パスではなく、「㩃啜敳獲啜敳屲灁」などの文字を入力します)。何が問題なのかわかりません。つまり、関連するソース コードは次のとおりです (インクルードなどは削除されています)。

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

どんな助けでも大歓迎です。

4

1 に答える 1

1

環境で UNICODE を定義していない限り、RegSetValueEx は (REG_SZ の場合) 渡すデータが Unicode であることを想定しています。しかし、.c_str はおそらく非 Unicode ストリームです。

于 2012-09-10T19:35:39.623 に答える