CRegKey regKey; if(regKey.Open(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion", KEY_READ) == ERROR_SUCCESS) { // Key opened successfully for reading // Use regKey to read values from the registry } else { // Failed to open key for reading }
CRegKey regKey; if(regKey.Open(HKEY_CURRENT_USER, "SOFTWARE\\ExampleApp", KEY_WRITE) == ERROR_SUCCESS) { // Key opened successfully for writing regKey.SetDWORDValue("SomeSetting", 123); } else { // Failed to open key for writing }In this example, the key "HKEY_CURRENT_USER\SOFTWARE\ExampleApp" is opened for writing using the KEY_WRITE access mode. The SetDWORDValue function is then used to write a DWORD value to the registry. Package/library: This code is using the MFC library.