From 19d5baa60e023f5d78110bdbb213a4c6232db932 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Kotiuk?= Date: Fri, 31 May 2024 12:01:48 +0200 Subject: [PATCH] fix: Converting LPCWSTR with QT6 --- src/winextras.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/winextras.cpp b/src/winextras.cpp index f0c266e12..a5328daf9 100644 --- a/src/winextras.cpp +++ b/src/winextras.cpp @@ -330,6 +330,14 @@ void WinExtras::removeFileAssociationFromRegistry() SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, 0, 0); } +// This functions works only with QT6 and newer C++ +const wchar_t *convertCharArrayToLPCWSTR(const char *charArray) +{ + wchar_t *wString = new wchar_t[1024]; + MultiByteToWideChar(CP_ACP, 0, charArray, -1, wString, 1024); + return wString; +} + /** * @brief Attempt to elevate process using runas * @return Execution status @@ -344,8 +352,13 @@ bool WinExtras::elevateAntiMicro() char *tempfile = ba.data(); tempverb[5] = '\0'; tempfile[antiProgramLocation.length()] = '\0'; +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + sei.lpVerb = convertCharArrayToLPCWSTR(tempverb); + sei.lpFile = convertCharArrayToLPCWSTR(tempfile); +#else sei.lpVerb = tempverb; sei.lpFile = tempfile; +#endif sei.hwnd = NULL; sei.nShow = SW_NORMAL; BOOL result = ShellExecuteEx(&sei);