QCoreApplication/Win: add a better way for ActiveQt to override qAppFileName
Right now, the DLLMain in qaxserverdll.cpp calls GetModuleFileName() on the hInstance for the DLL and passes the path to QCoreApplication to override the path. This adds a way for it to simply pass the hInstance handle, which will automatically cause qAppFileName() & QCoreApplication::applicationFilePath() return the DLL's path, which in turn influences the default QCoreApplication::libraryPaths(). Change-Id: I3cc172288c54c3938566fffdfb62985000ce2e9c Reviewed-by: Oliver Wolff <oliver.wolff@qt.io> (cherry picked from commit 507024317fec0c1deeb62c8c2ba5a43af7d65f21) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
2ed35fe889
commit
993c3fc35b
@ -132,6 +132,7 @@ public:
|
|||||||
std::unique_ptr<char *[]> origArgv;
|
std::unique_ptr<char *[]> origArgv;
|
||||||
|
|
||||||
bool consoleAllocated = false;
|
bool consoleAllocated = false;
|
||||||
|
static void *mainInstanceHandle; // HINSTANCE without <windows.h>
|
||||||
#endif
|
#endif
|
||||||
void appendApplicationPathToLibraryPaths(void);
|
void appendApplicationPathToLibraryPaths(void);
|
||||||
|
|
||||||
|
@ -20,6 +20,9 @@ QT_BEGIN_NAMESPACE
|
|||||||
|
|
||||||
using namespace Qt::StringLiterals;
|
using namespace Qt::StringLiterals;
|
||||||
|
|
||||||
|
// By default, we get the path to the host .exe. ActiveQt can override this
|
||||||
|
// with the component's DLL.
|
||||||
|
Q_CONSTINIT void *QCoreApplicationPrivate::mainInstanceHandle = nullptr;
|
||||||
QString qAppFileName() // get application file name
|
QString qAppFileName() // get application file name
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
@ -45,7 +48,8 @@ QString qAppFileName() // get application file name
|
|||||||
do {
|
do {
|
||||||
size += MAX_PATH;
|
size += MAX_PATH;
|
||||||
space.resize(int(size));
|
space.resize(int(size));
|
||||||
v = GetModuleFileName(NULL, space.data(), DWORD(space.size()));
|
auto hInstance = reinterpret_cast<HINSTANCE>(QCoreApplicationPrivate::mainInstanceHandle);
|
||||||
|
v = GetModuleFileName(hInstance, space.data(), DWORD(space.size()));
|
||||||
} while (Q_UNLIKELY(v >= size));
|
} while (Q_UNLIKELY(v >= size));
|
||||||
|
|
||||||
return QString::fromWCharArray(space.data(), v);
|
return QString::fromWCharArray(space.data(), v);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user