void CRegisterTestView::OnRegWrite()
{
// TODO: Add your command handler code here
HKEY hKey = NULL;
HKEY hCompanyKey = NULL;
DWORD dw;
RegCreateKeyEx(HKEY_CURRENT_USER,
_T("Software\\Purplesoft\\Info"),
0,
REG_NONE,
REG_OPTION_NON_VOLATILE,
KEY_READ | KEY_WRITE,
NULL,
&hCompanyKey,
&dw);
RegSetValueEx(hCompanyKey,
_T("Name"),
0,
REG_SZ,
(BYTE*)Organization,
(sizeof(Organization)/sizeof(Organization[0]) + 1)*sizeof(CHAR));
RegCloseKey(hKey);
}
忘写了以下两行代码,加上了还是不行。Debug时,Organization里已经赋上值了。
CHAR Organization[100];
strcpy(Organization, "ZengPurple");
修改后代码
void CRegisterTestView::OnRegWrite()
{
// TODO: Add your command handler code here
HKEY hCompanyKey = NULL;
DWORD dw;
LPCTSTR RegValueBuffer = _T("ZengPurple");//这是修改后的代码!!
DWORD dwAge = 30;
RegCreateKeyEx(HKEY_CURRENT_USER,
_T("Software\\Purplesoft\\Info"),
0,
REG_NONE,
REG_OPTION_NON_VOLATILE,
KEY_ALL_ACCESS,
NULL,
&hCompanyKey,
&dw);
RegSetValueEx(hCompanyKey,
_T("Name"),
0,
REG_SZ,
(CONST BYTE*)RegValueBuffer,
(lstrlen(RegValueBuffer) + 1)*sizeof(TCHAR));//这也做了修改
RegCloseKey(hCompanyKey);}