mirror of
https://github.com/HIllya51/LunaHook.git
synced 2024-12-27 13:44:11 +08:00
c94547bbc9
This reverts commit 975f049797bcd6b9de0e11f9a926d5ac3ec79ef8. 1 1 Revert "Update QtLoader_inline.cpp" This reverts commit 372dd2dc3e2f23c810f13e51437904fac1422c04. Update QtLoader_inline.cpp Update QtLoader_inline.cpp 1 1 1 Update CMakeLists.txt 1 1
72 lines
2.1 KiB
C++
72 lines
2.1 KiB
C++
#include<Windows.h>
|
|
#include<QApplication>
|
|
#include<QFont>
|
|
#include<QDir>
|
|
#include<thread>
|
|
#include<queue>
|
|
#include<mutex>
|
|
#include<Shlwapi.h>
|
|
#include<filesystem>
|
|
#include"../lockedqueue.hpp"
|
|
|
|
lockedqueue<std::wstring>waitingtask;
|
|
lockedqueue<HMODULE>waitingresult;
|
|
|
|
extern "C" __declspec(dllexport) int QtStartUp(std::vector<std::wstring>* dlls){
|
|
static bool once=false;
|
|
if(once)return 0;
|
|
once=true;
|
|
std::thread([=](){
|
|
for(int i=0;i<dlls->size();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<HMODULE>* QtLoadLibraryBatch(std::vector<std::wstring>* dlls){
|
|
std::lock_guard _(loadmutex);
|
|
static auto once=QtStartUp(dlls);
|
|
auto hdlls=new std::vector<HMODULE>;
|
|
for(int i=0;i<dlls->size();i++){
|
|
waitingtask.push(dlls->at(i));
|
|
hdlls->push_back(waitingresult.pop());
|
|
}
|
|
return hdlls;
|
|
}
|
|
#if 0
|
|
extern "C" __declspec(dllexport) std::vector<HMODULE>* QtLoadLibrary(std::vector<std::wstring>* dlls){
|
|
auto hdlls=new std::vector<HMODULE>;
|
|
auto mutex=CreateSemaphoreW(0,0,1,0);
|
|
std::thread([=](){
|
|
for(int i=0;i<dlls->size();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;i<dlls->size();i++)
|
|
hdlls->push_back(LoadLibraryW(dlls->at(i).c_str()));
|
|
ReleaseSemaphore(mutex,1,0);
|
|
app.exec();
|
|
|
|
}).detach();
|
|
WaitForSingleObject(mutex,INFINITE);
|
|
return hdlls;
|
|
}
|
|
#endif
|