diff --git a/src/GLideNUI-wtl/ConfigDlg.cpp b/src/GLideNUI-wtl/ConfigDlg.cpp index 87496e4a..96b77d92 100644 --- a/src/GLideNUI-wtl/ConfigDlg.cpp +++ b/src/GLideNUI-wtl/ConfigDlg.cpp @@ -438,13 +438,16 @@ public: GlideN64WtlModule * WtlModule = NULL; -void ConfigInit(void * hinst) { +extern "C" +{ +EXPORT void CALL ConfigInit(void * hinst) { WtlModule = new GlideN64WtlModule((HINSTANCE)hinst); } -void ConfigCleanup(void) { +EXPORT void CALL ConfigCleanup(void) { if (WtlModule) { delete WtlModule; WtlModule = NULL; } } +} diff --git a/src/GLideNUI-wtl/ConfigDlg.h b/src/GLideNUI-wtl/ConfigDlg.h index 7f401573..a0d15898 100644 --- a/src/GLideNUI-wtl/ConfigDlg.h +++ b/src/GLideNUI-wtl/ConfigDlg.h @@ -76,8 +76,3 @@ protected: uint32_t m_TabLeft, m_ProfileLeft; bool m_Saved; }; - -#ifdef _WIN32 -void ConfigInit(void * hinst); -void ConfigCleanup(void); -#endif \ No newline at end of file diff --git a/src/GLideNUI-wtl/GLideNUI.h b/src/GLideNUI-wtl/GLideNUI.h index 12312b46..fba02c6c 100644 --- a/src/GLideNUI-wtl/GLideNUI.h +++ b/src/GLideNUI-wtl/GLideNUI.h @@ -13,6 +13,8 @@ extern "C" { #define CALL #endif +EXPORT void CALL ConfigInit(void * hinst); +EXPORT void CALL ConfigCleanup(void); EXPORT bool CALL RunConfig(const wchar_t * _strFileName, const char * _romName, unsigned int _maxMSAALevel, unsigned int _maxAnisotropy); EXPORT int CALL RunAbout(const wchar_t * _strFileName); EXPORT void CALL LoadConfig(const wchar_t * _strFileName); diff --git a/src/GLideNUI/GLideNUI.cpp b/src/GLideNUI/GLideNUI.cpp index f1ffb2d8..ce9bb0d0 100644 --- a/src/GLideNUI/GLideNUI.cpp +++ b/src/GLideNUI/GLideNUI.cpp @@ -20,29 +20,21 @@ Q_IMPORT_PLUGIN(QWindowsVistaStylePlugin) inline void initMyResource() { Q_INIT_RESOURCE(icon); } inline void cleanMyResource() { Q_CLEANUP_RESOURCE(icon); } +static std::unique_ptr s_pQApp; +static QCoreApplication* s_pAppInstance; + static int openConfigDialog(const wchar_t * _strFileName, const char * _romName, unsigned int _maxMSAALevel, float _maxAnisotropy, bool & _accepted) { - cleanMyResource(); - initMyResource(); QString strIniFileName = QString::fromWCharArray(_strFileName); loadSettings(strIniFileName); if (config.generalEmulation.enableCustomSettings != 0 && _romName != nullptr && strlen(_romName) != 0) loadCustomRomSettings(strIniFileName, _romName); - std::unique_ptr pQApp; - QCoreApplication* pApp = QCoreApplication::instance(); - - if (pApp == nullptr) { - int argc = 0; - char * argv = 0; - pQApp.reset(new QApplication(argc, &argv)); - pApp = pQApp.get(); - } - QTranslator translator; - if (translator.load(getTranslationFile(), strIniFileName)) - pApp->installTranslator(&translator); + if (translator.load(getTranslationFile(), strIniFileName)) { + s_pAppInstance->installTranslator(&translator); + } ConfigDialog w(Q_NULLPTR, Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint, _maxMSAALevel, _maxAnisotropy); @@ -51,7 +43,7 @@ int openConfigDialog(const wchar_t * _strFileName, const char * _romName, unsign w.setTitle(); w.show(); - int res = pQApp ? pQApp->exec() : w.exec(); + int res = s_pQApp ? s_pQApp->exec() : w.exec(); _accepted = w.isAccepted(); return res; } @@ -59,20 +51,13 @@ int openConfigDialog(const wchar_t * _strFileName, const char * _romName, unsign static int openAboutDialog(const wchar_t * _strFileName) { - cleanMyResource(); - initMyResource(); - - int argc = 0; - char * argv = 0; - QApplication a(argc, &argv); - QTranslator translator; if (translator.load(getTranslationFile(), QString::fromWCharArray(_strFileName))) - a.installTranslator(&translator); + s_pAppInstance->installTranslator(&translator); AboutDialog w(Q_NULLPTR, Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint); w.show(); - return a.exec(); + return s_pQApp ? s_pQApp->exec() : w.exec(); } bool runConfigThread(const wchar_t * _strFileName, const char * _romName, unsigned int _maxMSAALevel, unsigned int _maxAnisotropy) { @@ -97,6 +82,26 @@ int runAboutThread(const wchar_t * _strFileName) { return 0; } +EXPORT void CALL ConfigInit(void * hinst) +{ + initMyResource(); + + s_pAppInstance = QCoreApplication::instance(); + + if (s_pAppInstance == nullptr) { + int argc = 0; + char * argv = 0; + s_pQApp.reset(new QApplication(argc, &argv)); + s_pAppInstance = s_pQApp.get(); + } +} + +EXPORT void CALL ConfigCleanup(void) +{ + cleanMyResource(); + s_pQApp.release(); +} + EXPORT bool CALL RunConfig(const wchar_t * _strFileName, const char * _romName, unsigned int _maxMSAALevel, unsigned int _maxAnisotropy) { return runConfigThread(_strFileName, _romName, _maxMSAALevel, _maxAnisotropy); diff --git a/src/GLideNUI/GLideNUI.h b/src/GLideNUI/GLideNUI.h index 7f6f142a..2fa41c57 100644 --- a/src/GLideNUI/GLideNUI.h +++ b/src/GLideNUI/GLideNUI.h @@ -7,12 +7,14 @@ extern "C" { #ifdef OS_WINDOWS #define EXPORT __declspec(dllexport) -#define CALL __cdecl +#define CALL __cdecl #else #define EXPORT __attribute__((visibility("default"))) #define CALL #endif +EXPORT void CALL ConfigInit(void * hinst); +EXPORT void CALL ConfigCleanup(void); EXPORT bool CALL RunConfig(const wchar_t * _strFileName, const char * _romName, unsigned int _maxMSAALevel, unsigned int _maxAnisotropy); EXPORT int CALL RunAbout(const wchar_t * _strFileName); EXPORT void CALL LoadConfig(const wchar_t * _strFileName); diff --git a/src/mupenplus/MupenPlusAPIImpl.cpp b/src/mupenplus/MupenPlusAPIImpl.cpp index f814d389..d94b31fb 100644 --- a/src/mupenplus/MupenPlusAPIImpl.cpp +++ b/src/mupenplus/MupenPlusAPIImpl.cpp @@ -11,6 +11,10 @@ #define DLSYM(a, b) dlsym(a, b) #endif // OS_WINDOWS +#ifdef M64P_GLIDENUI +#include "GLideNUI/GLideNUI.h" +#endif + ptr_ConfigGetSharedDataFilepath ConfigGetSharedDataFilepath = nullptr; ptr_ConfigGetUserConfigPath ConfigGetUserConfigPath = nullptr; ptr_ConfigGetUserDataPath ConfigGetUserDataPath = nullptr; @@ -103,6 +107,8 @@ m64p_error PluginAPI::PluginStartup(m64p_dynlib_handle _CoreLibHandle) Config_SetDefault(); } } +#else + ConfigInit(nullptr); #endif // M64P_GLIDENUI return M64ERR_SUCCESS; @@ -122,6 +128,9 @@ m64p_error PluginAPI::PluginShutdown() _callAPICommand(acRomClosed); delete m_pRspThread; m_pRspThread = nullptr; +#endif +#ifdef M64P_GLIDENUI + ConfigCleanup(); #endif return M64ERR_SUCCESS; } diff --git a/src/windows/GLideN64_windows.cpp b/src/windows/GLideN64_windows.cpp index 1da12745..0b3c5c7b 100644 --- a/src/windows/GLideN64_windows.cpp +++ b/src/windows/GLideN64_windows.cpp @@ -1,18 +1,13 @@ #include "GLideN64_Windows.h" +#include "GLideNUI/GLideNUI.h" HWND hWnd; HWND hStatusBar; HWND hToolBar; HINSTANCE hInstance; -#ifdef WTL_UI -void ConfigInit(void * hinst); -void ConfigCleanup(void); -#endif - BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD dwReason, LPVOID /*lpvReserved*/) { -#ifdef WTL_UI if (dwReason == DLL_PROCESS_ATTACH) { hInstance = hinstDLL; @@ -22,8 +17,5 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD dwReason, LPVOID /*lpvReserved*/) { ConfigCleanup(); } -#else - hInstance = hinstDLL; -#endif return TRUE; }