From 9701d6f318607d9d271eb79bf77d789c95ee0a64 Mon Sep 17 00:00:00 2001 From: luoliangyi <87842688@qq.com> Date: Thu, 30 Mar 2023 10:49:00 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E5=BA=94=E7=94=A8=E8=B0=83?= =?UTF-8?q?=E7=94=A8qt=20dll=E6=97=B6=EF=BC=8C=E5=BF=85=E9=A1=BB=E8=A6=81?= =?UTF-8?q?=E5=B0=86exe=E5=92=8Cqt=E4=BE=9D=E8=B5=96=E5=BA=93=E6=94=BE?= =?UTF-8?q?=E5=9C=A8=E4=B8=80=E8=B5=B7=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../HGDemo/HGDemo.pro | 2 + .../HGSaneUI/HGSaneUI.def | 0 .../HGSaneUI/HGSaneUI.pro | 7 +-- .../HGSolution2.pro | 0 modules/saneui/dllmain.cpp | 44 ++++++++++++++++++- 5 files changed, 48 insertions(+), 5 deletions(-) rename build-qt/{HGSolution => HGSolution2}/HGDemo/HGDemo.pro (97%) rename build-qt/{HGSolution => HGSolution2}/HGSaneUI/HGSaneUI.def (100%) rename build-qt/{HGSolution => HGSolution2}/HGSaneUI/HGSaneUI.pro (97%) rename build-qt/{HGSolution => HGSolution2}/HGSolution2.pro (100%) diff --git a/build-qt/HGSolution/HGDemo/HGDemo.pro b/build-qt/HGSolution2/HGDemo/HGDemo.pro similarity index 97% rename from build-qt/HGSolution/HGDemo/HGDemo.pro rename to build-qt/HGSolution2/HGDemo/HGDemo.pro index bf0e6ce7..9da2e244 100644 --- a/build-qt/HGSolution/HGDemo/HGDemo.pro +++ b/build-qt/HGSolution2/HGDemo/HGDemo.pro @@ -81,6 +81,7 @@ win32 { DESTDIR = ../../../../release/win/x86/Release/ } CONFIG(debug, debug|release) { + DESTDIR = ../../../build/windows/Debug } } contains(QT_ARCH, x86_64){ @@ -89,6 +90,7 @@ win32 { DESTDIR = ../../../../release/win/x64/Release/ } CONFIG(debug, debug|release) { + DESTDIR = ../../../build/windows/x64/Debug } } } diff --git a/build-qt/HGSolution/HGSaneUI/HGSaneUI.def b/build-qt/HGSolution2/HGSaneUI/HGSaneUI.def similarity index 100% rename from build-qt/HGSolution/HGSaneUI/HGSaneUI.def rename to build-qt/HGSolution2/HGSaneUI/HGSaneUI.def diff --git a/build-qt/HGSolution/HGSaneUI/HGSaneUI.pro b/build-qt/HGSolution2/HGSaneUI/HGSaneUI.pro similarity index 97% rename from build-qt/HGSolution/HGSaneUI/HGSaneUI.pro rename to build-qt/HGSolution2/HGSaneUI/HGSaneUI.pro index 91e2e8ae..1fad1f7f 100644 --- a/build-qt/HGSolution/HGSaneUI/HGSaneUI.pro +++ b/build-qt/HGSolution2/HGSaneUI/HGSaneUI.pro @@ -42,11 +42,9 @@ if (contains(DEFINES, OEM_HANWANG) || contains(DEFINES, OEM_LISICHENG) || contai } win32 { - SOURCES += ../../../modules/saneui/dllmain.cpp SOURCES += ../../../modules/saneui/qmfcapp.cpp SOURCES += ../../../modules/saneui/qwinhost.cpp SOURCES += ../../../modules/saneui/qwinwidget.cpp - HEADERS += ../../../modules/saneui/qmfcapp.h HEADERS += ../../../modules/saneui/qwinhost.h HEADERS += ../../../modules/saneui/qwinwidget.h @@ -117,6 +115,7 @@ win32 { DESTDIR = ../../../../release/win/x86/Release/ } CONFIG(debug, debug|release) { + DESTDIR = ../../../build/windows/Debug } } contains(QT_ARCH, x86_64){ @@ -125,6 +124,7 @@ win32 { DESTDIR = ../../../../release/win/x64/Release/ } CONFIG(debug, debug|release) { + DESTDIR = ../../../build/windows/x64/Debug } } } @@ -266,6 +266,7 @@ HEADERS += \ SOURCES += \ ../../../modules/saneui/HGSaneUI.cpp \ ../../../modules/saneui/dialog_device_scan.cpp \ - ../../../modules/saneui/dialog_device_select.cpp + ../../../modules/saneui/dialog_device_select.cpp \ + ../../../modules/saneui/dllmain.cpp diff --git a/build-qt/HGSolution/HGSolution2.pro b/build-qt/HGSolution2/HGSolution2.pro similarity index 100% rename from build-qt/HGSolution/HGSolution2.pro rename to build-qt/HGSolution2/HGSolution2.pro diff --git a/modules/saneui/dllmain.cpp b/modules/saneui/dllmain.cpp index d59b6f7b..2909c5c7 100644 --- a/modules/saneui/dllmain.cpp +++ b/modules/saneui/dllmain.cpp @@ -1,6 +1,10 @@ -#include "qmfcapp.h" +#include "base/HGDef.h" +#include "base/HGInc.h" +#include "base/HGUtility.h" + +#if defined (HG_CMP_MSC) +#include "qmfcapp.h" #include "qwinwidget.h" -#include HINSTANCE g_hInst = NULL; bool g_ownApplication = FALSE; @@ -10,6 +14,26 @@ BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpvReserved*/) if (dwReason == DLL_PROCESS_ATTACH) { g_hInst = hInstance; + + HGChar moduleName[512]; + HGBase_GetModuleName(DllMain, moduleName, 512); + HGChar modulePath[512]; + HGBase_GetFilePath(moduleName, modulePath, 512); + + char *env = getenv("QT_QPA_PLATFORM_PLUGIN_PATH"); + if (NULL == env) + { + char newEnv[256]; + sprintf(newEnv, "QT_QPA_PLATFORM_PLUGIN_PATH=%s", modulePath); + putenv(newEnv); + } + else if (NULL == strstr(env, modulePath)) + { + char *newEnv = new char [strlen(env) + 256]; + sprintf(newEnv, "QT_QPA_PLATFORM_PLUGIN_PATH=%s;%s", env, modulePath); + putenv(newEnv); + delete []newEnv; + } } else if (dwReason == DLL_PROCESS_DETACH) { @@ -20,3 +44,19 @@ BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpvReserved*/) return TRUE; } +#else + +void __attribute__((constructor)) global_load(void); +void __attribute__((destructor)) global_unload(void); + +void global_load(void) +{ + +} + +void global_unload(void) +{ + +} + +#endif