我在數據上鑄造(char *),並且我在註冊表中只獲取一個char值。如果 我不使用轉換msvc 2010告訴我參數類型LPCTSTR與const char *不兼容。C++ RegSetValueEx在註冊表中只設置一個字符值
有人可以幫我嗎?
HKEY hKey;
LPCTSTR sk = TEXT("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run");
LONG openRes = RegOpenKeyEx(HKEY_CURRENT_USER, sk, 0, KEY_ALL_ACCESS , &hKey);
if (openRes==ERROR_SUCCESS) {
printf("Success opening key.");
} else {
printf("Error opening key.");
}
LPCTSTR value = TEXT("SomeKey");
LPCTSTR data = L"TestData\0";
LONG setRes = RegSetValueEx (hKey, value, 0, REG_SZ, (LPBYTE)data, strlen(data)+1);
if (setRes == ERROR_SUCCESS) {
printf("Success writing to Registry.");
} else {
printf("Error writing to Registry.");
}
cout << setRes << endl;
LONG closeOut = RegCloseKey(hKey);
if (closeOut == ERROR_SUCCESS) {
printf("Success closing key.");
} else {
printf("Error closing key.");
}
湯姆,它在第三個問題最近幾個小時與窄字符和寬字符字符串的不一致使用有關。不要每次遇到問題時都在SO上編寫代碼,也許最好是查看整個代碼以消除這些不一致之處?也許,這篇文章可以幫助:http://msdn.microsoft.com/en-us/library/ff381407%28v=vs.85%29.aspx? – atzz 2010-12-19 21:09:46