Hello, I encountered a problem displaying data in the console when using the method with the RegQueryValueEx function. When extracting data from main (if you directly call a function) everything is displayed correctly. But if you place the function in the method, the cracks are displayed.
I want to make a universal method to access the registry. When cout is called in the body of the method, the data is also displayed normally, as soon as they are output. Cout in main is displayed nonsense. Most likely this is due to the encoding of the console itself, but I’m not sure and ask you for help. Wednesday VS2015.
Fragment of the latest version with the Registry class:
ER_CODE Registry::GetOsVersion(HKEY mainKey, LPCTSTR keyPath, LPCTSTR keyValue, LPSTR ®istryData) { HKEY key; DWORD regtype; DWORD reg; TCHAR data[256]; if (RegOpenKeyEx(mainKey, keyPath, NULL, KEY_READ, &key) == ERROR_SUCCESS) { if (RegQueryValueEx(key, keyValue, NULL, ®type, (LPBYTE)&data, ®) == ERROR_SUCCESS) { if (regtype == REG_SZ) { registryData = data; RegCloseKey(key); return SUCCESS; } else return WARNING; } else return WARNING; } else return WARNING; } int main() { LPTSTR regData; ER_CODE eCode; Registry reg; eCode = reg.GetOsVersion(HKEY_LOCAL_MACHINE,TEXT("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion"), TEXT("ProductName"), regData); if (eCode == SUCCESS) { printf("%-20s\n",regData); } system("pause"); return NULL; }