123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 |
- #include "settingAPI.h"
- #include <QLibrary>
- #include <QCoreApplication>
- #include <QDebug>
- using funcInit = int (*)(const stInitData* pData);
- using funcCreateWindow = int (*)(int nSkinType, QWidget* parent);
- using funcShowWindow = int (*)(int nSkinType, int nServiceID, bool bShowWindow);
- using funcGetChangedData = int (*)(QString& data);
- using funcSave = int (*)(const int);
- using funcRelease = int (*)();
- funcInit g_pFuncInit = nullptr;
- funcCreateWindow g_pFuncCreateWindow = nullptr;
- funcShowWindow g_pFuncShowWindow = nullptr;
- funcGetChangedData g_pFuncGetChangedData = nullptr;
- funcSave g_pFuncSaveData = nullptr;
- funcRelease g_pFuncRelease = nullptr;
- bool g_isLoaded = false;
- /**
- * @brief 加载设置动态库
- *
- * @return true
- * @return false
- */
- bool loadSettingLibrary()
- {
- if(g_isLoaded)
- {
- return true; // 已经加载过
- }
- QString strLibPath = QCoreApplication::applicationDirPath() + "/libACAServerSetting.dll";
- QLibrary lib(strLibPath);
- if(!lib.load())
- {
- qWarning() << "Failed to load library:" << strLibPath << lib.errorString();
- return false;
- }
- g_pFuncInit = reinterpret_cast<funcInit>(lib.resolve("DoInit"));
- g_pFuncCreateWindow = reinterpret_cast<funcCreateWindow>(lib.resolve("DoCreateWindow"));
- g_pFuncShowWindow = reinterpret_cast<funcShowWindow>(lib.resolve("DoShowWindow"));
- g_pFuncGetChangedData = reinterpret_cast<funcGetChangedData>(lib.resolve("DoGetChangedData"));
- g_pFuncSaveData = reinterpret_cast<funcSave>(lib.resolve("DoSave"));
- g_pFuncRelease = reinterpret_cast<funcRelease>(lib.resolve("DoRelease"));
- if(!g_pFuncInit || !g_pFuncCreateWindow || !g_pFuncShowWindow || !g_pFuncGetChangedData || !g_pFuncSaveData || !g_pFuncRelease)
- {
- qWarning() << "Failed to resolve functions in library:" << strLibPath;
- return false;
- }
- g_isLoaded = true;
- qDebug() << "Library loaded successfully:" << strLibPath;
- return true;
- }
- int DoInit(const stInitData* pData)
- {
- if(g_pFuncInit == nullptr)
- {
- qDebug() << "Function DoInit is not resolved.";
- return -1; // 函数未解析
- }
- return g_pFuncInit(pData);
- }
- int DoCreateWindow(int nSkinType, QWidget* parent)
- {
- if(g_pFuncCreateWindow == nullptr)
- {
- qDebug() << "Function DoCreateWindow is not resolved.";
- return -1; // 函数未解析
- }
- return g_pFuncCreateWindow(nSkinType, parent);
- }
- int DoShowWindow(int nSkinType, int nServiceID, bool bShowWindow)
- {
- if(g_pFuncShowWindow == nullptr)
- {
- qDebug() << "Function DoShowWindow is not resolved.";
- return -1; // 函数未解析
- }
- return g_pFuncShowWindow(nSkinType, nServiceID, bShowWindow);
- }
- int DoGetChangedData(QString& strData)
- {
- if(g_pFuncGetChangedData == nullptr)
- {
- qDebug() << "Function DoGetChangedData is not resolved.";
- return -1; // 函数未解析
- }
- return g_pFuncGetChangedData(strData);
- }
- int DoSave(const int nServiceID)
- {
- if(g_pFuncSaveData == nullptr)
- {
- qDebug() << "Function DoSaveData is not resolved.";
- return -1; // 函数未解析
- }
- return g_pFuncSaveData(nServiceID);
- }
- int DoRelease()
- {
- if(g_pFuncRelease == nullptr)
- {
- qDebug() << "Function DoRelease is not resolved.";
- return -1; // 函数未解析
- }
- return g_pFuncRelease();
- }
|