#include <windows.h>#include <iostream>using namespace std;int main(int argc, char ** argv){ // loading dll manualy HMODULE hModule = LoadLibrary("fwdll.dll"); // Importing DLLInit() function from DLL typedef void (*PDLLInit)(); PDLLInit pDllInit = (PDLLInit)GetProcAddress(hModule, "DLLInit"); pDllInit(); /* .... Что-то делаем .... */ BOOL b = FreeLibrary(hModule); return 0;}
extern "C" __declspec(dllexport) void DLLInit(){ // FWDLLServer - наследник QServerSocket FWDLLServer* DLLserver = new FWDLLServer();}
// решение в лобextern "C" __declspec(dllexport) void DLLInit(){ int argcc = 0; QApplication* app = new QApplication(argcc, 0, FALSE); FWDLLServer* DLLServer = new FWDLLServer(); app.exec();}
FWDLLServer * DLLServer = 0;extern "C" __declspec(dllexport) void DLLInit() { int argcc = 0; new QApplication(argcc, 0, FALSE); // глобальный указатель хранится в qApp DLLServer = new FWDLLServer(); }
extern "C" __declspec(dllexport) void DLLDestroy() { delete DLLServer; delete qApp;}
extern "C" __declspec(dllexport) void DLLProcessEvents() { qApp->processEvents();}
BOOL WINAPI DllMain( HINSTANCE hInstance, DWORD dwReason, LPVOID lpvReserved ){ static bool ownApplication = FALSE; if ( dwReason == DLL_PROCESS_ATTACH ) ownApplication = QMfcApp::pluginInstance( hInstance ); if ( dwReason == DLL_PROCESS_DETACH && ownApplication ) delete qApp; return TRUE;}
QApplication *pApp;bool APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved){ int argc = 0; switch (ul_reason_for_call){ case DLL_PROCESS_ATTACH: pApp = new QApplication(argc, 0); break;case DLL_THREAD_ATTACH:case DLL_THREAD_DETACH: break;case DLL_PROCESS_DETACH: delete pApp; break; } return TRUE;}
//main.cppint main(int argc, char ** argv){//...DLLInit(); while(!exitCondition) { // .... pDllProcessEvents(); Sleep(1); }// ...}
connect( s, SIGNAL(readyRead()), this, SLOT(readClient()) );
void connectionCallback( int client );void readDataCallback( int client, const char * data, int dataSize );...int main( int argc, char ** argv ){... while ( not_end_of_cycle ) { qtDllProcessEvents(); // тут смикаються калбеки... // оброблюємо дані та все таке }...}