CRegKey regKey; regKey.Open(HKEY_CURRENT_USER, _T("Software\\Example")); DWORD value; if(regKey.QueryDWORDValue(_T("ExampleValue"), value) == ERROR_SUCCESS) { // The value of the "ExampleValue" registry key was successfully retrieved // Do something with the retrieved value }
BOOL RetrieveRegistryValue(DWORD& value) { CRegKey regKey; LONG result = regKey.Open(HKEY_LOCAL_MACHINE, _T("Software\\MyApp")); if(result == ERROR_SUCCESS) { result = regKey.QueryDWORDValue(_T("MyValue"), value); } return (result == ERROR_SUCCESS); }In this example, we define a function that retrieves the value of a registry key named "MyValue" under the "Software\MyApp" key of the HKEY_LOCAL_MACHINE root key. We create a new CRegKey object, open the registry key, and then call QueryDWORDValue to retrieve the value. If the function succeeds, it returns TRUE, and the retrieved value is stored in the "value" reference parameter. The package library for CRegKey is part of the Windows SDK or MFC library.