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 49 50
|
BOOL WriteStringToRegistry(HKEY hKey, LPTSTR lpValue, LPTSTR lpContent)
{
LONG lRv;
if (lpContent==NULL) return TRUE; // ignore
lRv=RegSetValueEx(hKey,
lpValue,
0,
REG_SZ,
(LPBYTE) lpContent,
(_tcslen(lpContent)+1)*sizeof(TCHAR));
return (lRv==ERROR_SUCCESS);
}
BOOL WriteStringToRegistryOrDeleteIfEmpty(HKEY hKey, LPTSTR lpValue, LPTSTR lpContent)
{
LONG lRv;
if (lpContent==NULL) return TRUE; // ignore
if (_tcscmp(lpContent,TEXT(""))!=0) return WriteStringToRegistry(hKey,lpValue,lpContent);
lRv=RegDeleteValue(hKey,
lpValue);
return (lRv==ERROR_SUCCESS)||(lRv==ERROR_FILE_NOT_FOUND);
}
BOOL WriteDWordToRegistry(HKEY hKey, LPTSTR lpValue, DWORD dwContent)
{
LONG lRv;
lRv=RegSetValueEx(hKey,
lpValue,
0,
REG_DWORD,
(LPBYTE) &dwContent,
sizeof(DWORD));
return (lRv==ERROR_SUCCESS);
}
BOOL WriteBoolToRegistry(HKEY hKey, LPTSTR lpValue, BOOL bContent)
{
if (bContent) {
return WriteStringToRegistry(hKey,lpValue,TEXT("1"));
} else {
return WriteStringToRegistry(hKey,lpValue,TEXT("0"));
}
} |
Partager