#include #include #include #include #include #include #include #include #include #include"../lockedqueue.hpp" lockedqueuewaitingtask; lockedqueuewaitingresult; extern "C" __declspec(dllexport) int QtStartUp(std::vector* dlls){ static bool once=false; if(once)return 0; once=true; std::thread([=](){ for(int i=0;isize();i++) QApplication::addLibraryPath(QString::fromStdWString(std::filesystem::path(dlls->at(i)).parent_path())); int _=0; QApplication app(_, nullptr); app.setFont(QFont("MS Shell Dlg 2", 10)); while(true) { if(!waitingtask.empty()) { auto top=waitingtask.pop(); waitingresult.push(LoadLibraryW(top.c_str())); } app.processEvents(0); } }).detach(); return 0; } std::mutex loadmutex; extern "C" __declspec(dllexport) std::vector* QtLoadLibraryBatch(std::vector* dlls){ std::lock_guard _(loadmutex); static auto once=QtStartUp(dlls); auto hdlls=new std::vector; for(int i=0;isize();i++){ waitingtask.push(dlls->at(i)); hdlls->push_back(waitingresult.pop()); } return hdlls; } #if 0 extern "C" __declspec(dllexport) std::vector* QtLoadLibrary(std::vector* dlls){ auto hdlls=new std::vector; auto mutex=CreateSemaphoreW(0,0,1,0); std::thread([=](){ for(int i=0;isize();i++) QApplication::addLibraryPath(QString::fromStdWString(std::filesystem::path(dlls->at(i)).parent_path())); int _=0; QApplication app(_, nullptr); app.setFont(QFont("MS Shell Dlg 2", 10)); for(int i=0;isize();i++) hdlls->push_back(LoadLibraryW(dlls->at(i).c_str())); ReleaseSemaphore(mutex,1,0); app.exec(); }).detach(); WaitForSingleObject(mutex,INFINITE); return hdlls; } #endif