就以
[HKEY_USERS\.DEFAULT\keyboard layout\preload\4]
默认="E012345"为例子。
把E0210804读出来跟特定的字符串MYString进行比较。
/*
* read a string from the profile into pResult.
* result is number of bytes written into pResult
*/
DWORD mmGetProfileString( LPCTSTR pstrAppName, LPCTSTR pstrValueName, LPCTSTR
pDefault, LPTSTR pResult, DWORD &dwResult )
{
CString strName;
HKEY hkey;
DWORD dwType;
LPBYTE pData;
strName.Format( _T("%s%s"), KEYNAME, pstrAppName );
if( RegOpenKey( ROOTKEY, strName, &hkey ) == ERROR_SUCCESS )
{
LONG lResult;
lResult = RegQueryValueEx( hkey, pstrValueName, NULL, &dwType,
NULL, &dwResult );
if( lResult == ERROR_SUCCESS )
{
pData = new BYTE[dwResult];
lResult = RegQueryValueEx( hkey, pstrValueName, NULL,
&dwType, (LPBYTE)pData, &dwResult ); if( lResult == ERROR_SUCCESS )
{
if( dwType == REG_SZ ) {
// cbResult is set to the size including null
_tcscpy( pResult, (LPCTSTR)pData );
RegCloseKey( hkey );
return( dwResult - 1 );
}
}
RegCloseKey(hkey);
delete [] pData;
}
}
// if we got here, we didnt find it, or it was the wrong type - return
// the default string
_tcscpy( pResult, pDefault );
return( _tcslen( pDefault ) * sizeof(_TCHAR) );
}
::RegOpenKeyEx
::RegQueryValueEx
樓上的已經講的很明白了
比较字符串用 strcmp / strncmp / _strcmpi
up
::RegOpenKeyEx
::RegQueryValueEx