I load my qt-dll by button clicking:
Code:
void CMFCTestDlg::OnBnClickedButton1() { HINSTANCE hinstLib; MYPROC ProcAdd; BOOL fFreeResult, fRunTimeLinkSuccess = FALSE; // Get a handle to the DLL module. hinstLib = LoadLibrary(TEXT("qttest.dll")); // If the handle is valid, try to get the function address. if (hinstLib != NULL) { ProcAdd = (MYPROC) GetProcAddress(hinstLib, "createWindow"); // If the function address is valid, call the function. if (NULL != ProcAdd) { fRunTimeLinkSuccess = TRUE; char * params[] = {"1"}; (ProcAdd) (1, params); } // Free the DLL module. fFreeResult = FreeLibrary(hinstLib); } // If unable to call the DLL function, use an alternative. if (! fRunTimeLinkSuccess) MessageBox(L"Message printed from executable\n"); }
Function createWindow() is as follows:
Code:
extern "C" __declspec(dllexport) int createWindow(int argc, char *argv[]) { Q_CHECK_PTR( qApp ); MainWindow* w = MainWindow::getInstance(); qApp->setMainWidget(w); w->show(); return qApp->exec(); }
When I click button then MainWindow appears, I close that window and then I click button again -- raising up assert: qcoreapplication: there should be only one application object...
Then I wrote the following code:
But now i'm getting error in _CrtIsValidHeapPointer method after second closing of MainWindow.
How to unload qt-dll correctly?