Please help me how to assign a value! I don't know how to translate from String to TCHAR for writing to the reg_sz registry
string par = "1234.32.23";
_TCHAR szTestString[] = _T(pra);
Full Code
string par = "1234.32.23";
HKEY ProxyServerKey;
RegCreateKeyExW(HKEY_CURRENT_USER, L"Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &ProxyServerKey, NULL);
_TCHAR szTestString[] = _T(par);
RegSetValueExW(ProxyServerKey, L"ProxyServer", 0, REG_SZ, (BYTE*)szTestString, sizeof(szTestString));
RegCloseKey(ProxyServerKey);
SendNotifyMessageW(HWND_BROADCAST, WM_SETTINGCHANGE, 0, 0);
You can't use the
_T()macro to convert data at runtime. It only works on char/string literals at compile-time.The best solution is to just use a
std::wstringinstead. You can pass its data directly toRegSetValueExW(), there is no need to copy it into a_TCHAR[]buffer at all, eg:Otherwise, if you need to keep using
std::stringfor whatever reason, but want to useRegSetValueExW(), then you will have to convert thechardata towchar_tat runtime usingMultiByteToWideChar()or equivalent, eg:Otherwise, just use
RegSetValueExA()instead, and let it convert fromchartowchar_tinternally for you, eg: