1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
|
LPTSTR CGPSInitializationData::GetRegistryString(
LPCTSTR p_SubKey,
LPCTSTR p_ValueName,
LPTSTR p_DefaultResult,
LPTSTR p_Buffer)
{
HKEY l_hKey = NULL;
DWORD l_dwType = 0;
LONG l_Result = 0;
DWORD l_Disposition = 0;
TCHAR l_LocalBuffer[256] = {0};
DWORD l_dwSize = sizeof(l_LocalBuffer);
_tcscpy(p_Buffer, p_DefaultResult);
if ( ::RegCreateKeyEx(HKEY_LOCAL_MACHINE, p_SubKey, 0, NULL,
0, 0, NULL, &l_hKey, &l_Disposition) == ERROR_SUCCESS )
{
l_Result = ::RegQueryValueEx(l_hKey, p_ValueName, NULL, &l_dwType, (BYTE*)l_LocalBuffer, &l_dwSize);
RegCloseKey(l_hKey);
if (l_Result == ERROR_SUCCESS)
_tcscpy(p_Buffer, l_LocalBuffer);
}
return p_Buffer;
}
bool CGPSInitializationData::WriteRegistryString(
LPCTSTR p_SubKey,
LPCTSTR p_ValueName,
LPCTSTR p_Data)
{
HKEY l_hKey = NULL;
LONG l_Result = 0;
DWORD l_Disposition = 0;
DWORD l_dwType = REG_SZ;
DWORD l_dwSize = (DWORD)(_tcslen(p_Data) + 1) * sizeof(TCHAR);
if (::RegCreateKeyEx(HKEY_LOCAL_MACHINE, p_SubKey, 0, NULL,
0, 0, NULL, &l_hKey, &l_Disposition) == ERROR_SUCCESS )
{
l_Result = ::RegSetValueEx(l_hKey, p_ValueName, NULL, l_dwType, (BYTE*)p_Data, l_dwSize);
RegCloseKey(l_hKey);
return (l_Result == ERROR_SUCCESS);
}
return false;
} |