Skip to content

Commit 19d5baa

Browse files
committed
fix: Converting LPCWSTR with QT6
1 parent 4f9f917 commit 19d5baa

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/winextras.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,14 @@ void WinExtras::removeFileAssociationFromRegistry()
330330
SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, 0, 0);
331331
}
332332

333+
// This functions works only with QT6 and newer C++
334+
const wchar_t *convertCharArrayToLPCWSTR(const char *charArray)
335+
{
336+
wchar_t *wString = new wchar_t[1024];
337+
MultiByteToWideChar(CP_ACP, 0, charArray, -1, wString, 1024);
338+
return wString;
339+
}
340+
333341
/**
334342
* @brief Attempt to elevate process using runas
335343
* @return Execution status
@@ -344,8 +352,13 @@ bool WinExtras::elevateAntiMicro()
344352
char *tempfile = ba.data();
345353
tempverb[5] = '\0';
346354
tempfile[antiProgramLocation.length()] = '\0';
355+
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
356+
sei.lpVerb = convertCharArrayToLPCWSTR(tempverb);
357+
sei.lpFile = convertCharArrayToLPCWSTR(tempfile);
358+
#else
347359
sei.lpVerb = tempverb;
348360
sei.lpFile = tempfile;
361+
#endif
349362
sei.hwnd = NULL;
350363
sei.nShow = SW_NORMAL;
351364
BOOL result = ShellExecuteEx(&sei);

0 commit comments

Comments
 (0)