I tried to access the Windows Registry with this Code:
CRegKey key;
LPTSTR szBuffer = new TCHAR[50];
ULONG cchBuffer = 257;
key.Open(HKEY_CURRENT_USER, L"HARDWARE", KEY_READ);
ULONG chars;
CString str;
if (key.QueryStringValue(L"Test", 0, &chars) == ERROR_SUCCESS)
{
key.QueryStringValue(L"Test", str.GetBuffer(chars), &chars);
str.ReleaseBuffer();
}
key.Close();
It returned an Error of the Microsoft Visual C++ Runtime Library:
Debug Assertation Failed!
Program: …
File: C:\Program Files\Microsoft Visual Studio
11.0\VC\ATLMFC\INCLUDE\altbase.h Line: 6146Expression: m_hkey != 0
For information Blah blah
After pressing Ignore it crashes.
I’m not sure what compiler is used because I (think I have) configured Qt Creator to use Visual C++ but the output Directory os called …_._MinGW_Qt_SDK_DEBUG
What to do now?
I don’t have a Windows machine nearby, but I think that there is no subkey named
HARDWAREintoHKEY_CURRENT_USER: it is intoHKEY_LOCAL_MACHINE.That, added to the fact that you are not checking the
Opencall for errors suggests that what you really want to do is:Anyway, it is always a good idea to handle the error, just in case.