RegQueryValueEx + DWORD problem
-
Hi I need to use 'RegQueryValueEx(...)' to retrieve a subkey's value.
CString strReturnWaarde(""); long lResult=0L; DWORD dwLength=0L, dwType=0L; TCHAR keyValue[256]; HKEY SrcKey; if ( RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Software\\COMPANY\\PRODUCT\\" + strKey, 0, KEY_READ, &SrcKey) == ERROR_SUCCESS ) { dwLength = 256*sizeof(TCHAR); lResult = RegQueryValueEx(SrcKey,strKeyName, NULL, &dwType, (BYTE*)keyValue, &dwLength ); if ( lResult == ERROR_SUCCESS ) { strReturnWaarde = CString(keyValue); } RegCloseKey(SrcKey); } ::AfxMessageBox(strReturnWaarde);
This code works when getting Text but not when trying to get numbers (DWORD). What is wrong with it? :x I replaced the 'strReturnWaarde' as ' int iReturnWaarde' and without the conversation to CString ofcourse. Greetings Jens -
Hi I need to use 'RegQueryValueEx(...)' to retrieve a subkey's value.
CString strReturnWaarde(""); long lResult=0L; DWORD dwLength=0L, dwType=0L; TCHAR keyValue[256]; HKEY SrcKey; if ( RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Software\\COMPANY\\PRODUCT\\" + strKey, 0, KEY_READ, &SrcKey) == ERROR_SUCCESS ) { dwLength = 256*sizeof(TCHAR); lResult = RegQueryValueEx(SrcKey,strKeyName, NULL, &dwType, (BYTE*)keyValue, &dwLength ); if ( lResult == ERROR_SUCCESS ) { strReturnWaarde = CString(keyValue); } RegCloseKey(SrcKey); } ::AfxMessageBox(strReturnWaarde);
This code works when getting Text but not when trying to get numbers (DWORD). What is wrong with it? :x I replaced the 'strReturnWaarde' as ' int iReturnWaarde' and without the conversation to CString ofcourse. Greetings JensHi, The problem is in typcasting. It is right to cast the type into a pointer to byte (LPBYTE) but then you have to provide the adress of your DWORD variable too. Also keyValue must be of type DWORD. Like:
DWORD dwType,dwLength,keyValue; ... RegResult=::RegQueryValueEx(SrcKey,strKeyName,NULL,&dwType,(LPBYTE)&(keyValue),&dwLength);
You may not use a TCHAR buffer array for this purpose. I couldn't find a way to cast this in a DWORD.;) Regards G. Steudtel