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().

Pick-to: 6.9
Change-Id: I3cc172288c54c3938566fffdfb62985000ce2e9c
Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
This commit is contained in:
Thiago Macieira 2025-01-16 19:54:05 -08:00
parent 08cd38078e
commit 507024317f
2 changed files with 6 additions and 1 deletions

View File

@ -130,6 +130,7 @@ public:
std::unique_ptr<char *[]> origArgv;
bool consoleAllocated = false;
static void *mainInstanceHandle; // HINSTANCE without <windows.h>
#endif
void appendApplicationPathToLibraryPaths(void);

View File

@ -20,6 +20,9 @@ QT_BEGIN_NAMESPACE
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
{
/*
@ -45,7 +48,8 @@ QString qAppFileName() // get application file name
do {
size += MAX_PATH;
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));
return QString::fromWCharArray(space.data(), v);