im developing a QT application, and I need to include clean C code. When I compile this code in code :: blocks, it was successful, perhaps with one warning, but when I try to compile it in the QT creator, I get these 4 errors.
cannot convert 'char*' to 'WCHAR*' for argument '1' to 'UINT GetSystemDirectoryW(WCHAR*, UINT)' cannot convert 'char*' to 'const WCHAR*' for argument '1' to 'HINSTANCE__* LoadLibraryW(const WCHAR*)' cannot convert 'char*' to 'WCHAR*' for argument '1' to 'BOOL cannot convert 'const char*' to 'const WCHAR*' for argument '2' to 'LONG RegQueryValueExW(HKEY__*, const WCHAR*, DWORD*, DWORD*, BYTE*, DWORD*)'
and the code is here>
char systemDirectory[MAX_PATH]; GetSystemDirectory(systemDirectory, MAX_PATH); //first error char kbdLayoutFilePath[MAX_PATH]; kbdLibrary = LoadLibrary(kbdLayoutFilePath); //second error char kbdName[KL_NAMELENGTH]; GetKeyboardLayoutName(kbdName); //third error if(RegQueryValueEx(hKey, "Layout File", NULL, &varType, layoutFile, &bufferSize) != ERROR_SUCCESS) //fourth error
I also use the snprintf function, so I cannot just change the type from char to WCHAR, because then it will not compile snprintf
snprintf(kbdKeyPath, 51 + KL_NAMELENGTH, "SYSTEM\\CurrentControlSet\\Control\\Keyboard Layouts\\%s", kbdName);
Do you have any idea how to fix this? At first I tried to change the type from char to WCHAR, but then snprintf did not work, so I tried to use swprinf, but without success, as it is strange he did not find this function
int swprintf(wchar_t *wcs, size_t maxlen, const wchar_t *format, ...);
but only that
int swprintf(wchar_t *wcs, const wchar_t *format, ...);
So what is my option? How to compile pure C code in a C ++ environment without any errors ... or how to make the correct type conversion.