Skip to content

Commit

Permalink
fix: Converting LPCWSTR with QT6
Browse files Browse the repository at this point in the history
  • Loading branch information
pktiuk committed May 31, 2024
1 parent 4f9f917 commit 19d5baa
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/winextras.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand Down

0 comments on commit 19d5baa

Please sign in to comment.