在wince6.0 随便找个例子看看
BOOL CApplicationPropPage::WriteRegistrySettings()
{
DEBUGMSG (1, (L"CApplicationPropPage::WriteRegistrySettings() \n"));
/******************************************************/
/* Set RDP Connection-specific values to the registry */
/******************************************************/
HKEY hKeyConnection;
TCHAR szPath [s_MAX_PATHLEN] = {0};
StringCchCopy(szPath, s_MAX_PATHLEN, REG_TSC_PATH);
StringCchCat(szPath, s_MAX_PATHLEN, L"\\");
StringCchCat(szPath, s_MAX_PATHLEN, m_pConnMgr->m_szConnectionName);
// Open the specified connection key
DWORD dwResult = RegOpenKeyEx(HKEY_CURRENT_USER, szPath,
0, KEY_WRITE, &hKeyConnection);
if (dwResult != ERROR_SUCCESS)
{
LPCTSTR pszErrorTitle = LoadStringEx (IDS_REG_SET_FAILED);
LPCTSTR pszMsg = LoadStringEx (IDS_REG_SET_FAILED_MESSAGE);
TCHAR szMsg [MAX_DISPLAY_STRING] = {0};
wsprintf (szMsg, pszMsg, GetLastError());
MessageBox (szMsg, pszErrorTitle, MB_ICONINFORMATION | MB_OK);
return FALSE;
}
// For the Application page, check to see what the user has selected
if (m_bDesktop)
{
dwResult = RegSetValueEx(hKeyConnection, PROP_STARTPROGRAM, 0, REG_SZ,
(BYTE *)(_T("")), (wcslen(_T("")) * sizeof(TCHAR))
+ sizeof(TCHAR));
if (dwResult != ERROR_SUCCESS)
{
LPCTSTR pszErrorTitle = LoadStringEx (IDS_REG_SET_FAILED);
LPCTSTR pszMsg = LoadStringEx (IDS_REG_SET_FAILED_MESSAGE);
TCHAR szMsg [MAX_DISPLAY_STRING] = {0};
wsprintf (szMsg, pszMsg, GetLastError());
MessageBox (szMsg, pszErrorTitle, MB_ICONINFORMATION | MB_OK);
// Close key
RegCloseKey(hKeyConnection);
return FALSE;
}
// Delete "Desktop" and "Shell Working Directory" values from the registry
RegDeleteValue(hKeyConnection, _T("Desktop"));
RegDeleteValue(hKeyConnection, PROP_WORKDIR);
}
else
{
DWORD dwDesktop = 2;
dwResult = RegSetValueEx(hKeyConnection, _T("Desktop"), 0 , REG_DWORD,
(BYTE *)&dwDesktop, sizeof(DWORD));
if (dwResult != ERROR_SUCCESS)
{
LPCTSTR pszErrorTitle = LoadStringEx (IDS_REG_SET_FAILED);
LPCTSTR pszMsg = LoadStringEx (IDS_REG_SET_FAILED_MESSAGE);
TCHAR szMsg [MAX_DISPLAY_STRING] = {0};
wsprintf (szMsg, pszMsg, GetLastError());
MessageBox (szMsg, pszErrorTitle, MB_ICONINFORMATION | MB_OK);
// Close key
RegCloseKey(hKeyConnection);
return FALSE;
}
dwResult = RegSetValueEx(hKeyConnection, PROP_STARTPROGRAM, 0, REG_SZ,
(BYTE *)(LPTSTR)m_szAlternateShell,
(wcslen((LPTSTR)m_szAlternateShell) * sizeof(TCHAR))
+ sizeof(TCHAR));
if (dwResult != ERROR_SUCCESS)
{
LPCTSTR pszErrorTitle = LoadStringEx (IDS_REG_SET_FAILED);
LPCTSTR pszMsg = LoadStringEx (IDS_REG_SET_FAILED_MESSAGE);
TCHAR szMsg [MAX_DISPLAY_STRING] = {0};
wsprintf (szMsg, pszMsg, GetLastError());
MessageBox (szMsg, pszErrorTitle, MB_ICONINFORMATION | MB_OK);
// Close key
RegCloseKey(hKeyConnection);
return FALSE;
}
dwResult = RegSetValueEx(hKeyConnection, PROP_WORKDIR, 0, REG_SZ,
(BYTE *)(LPTSTR)m_szShellWorkingDirectory,
(wcslen((LPTSTR)m_szShellWorkingDirectory) * sizeof(TCHAR))
+ sizeof(TCHAR));
if (dwResult != ERROR_SUCCESS)
{
LPCTSTR pszErrorTitle = LoadStringEx (IDS_REG_SET_FAILED);
LPCTSTR pszMsg = LoadStringEx (IDS_REG_SET_FAILED_MESSAGE);
TCHAR szMsg [MAX_DISPLAY_STRING] = {0};
StringCchPrintf (szMsg, MAX_DISPLAY_STRING, pszMsg, GetLastError());
MessageBox (szMsg, pszErrorTitle, MB_ICONINFORMATION | MB_OK);
// Close key
RegCloseKey(hKeyConnection);
return FALSE;
}
}
// Close key
RegCloseKey(hKeyConnection);
/*******************************************************************************/
// Put up the wait cursor
HCURSOR hOldCursor = SetCursor (LoadCursor (NULL, IDC_WAIT));
// Flush the MSTSC key
HKEY hKeyFlush;
RegOpenKeyEx(HKEY_CURRENT_USER, REG_TSC_PATH, 0, KEY_WRITE, &hKeyFlush);
RegFlushKey(hKeyFlush);
RegCloseKey(hKeyFlush);
// Flush the registered connections key
RegOpenKeyEx(HKEY_LOCAL_MACHINE, REGISTRATION_CONNECTIONS_KEY, 0, KEY_WRITE, &hKeyFlush);
RegFlushKey(hKeyFlush);
RegCloseKey(hKeyFlush);
// Remove the wait cursor
SetCursor (hOldCursor);
/*******************************************************************************/
return TRUE;
}
如果对linux,Android,wince 等嵌入式底层有兴趣的,请加这个QQ群吧,群号:27100460
在 RegCloseKey 之前调用。
在MSDN 介绍了这个函数的作用
This function writes all the attributes of the specified open registry key into the registry.
写入注册表。在 RegCloseKey 之前调用。
如果对linux,Android,wince 等嵌入式底层有兴趣的,请加这个QQ群吧,群号:27100460