PDA

View Full Version : QT DLL and MFC



mlheese
9th October 2010, 00:27
I compiled both a Release and Debug version of the QtWinMigrate qtdll example. I made no changes to anything in the source or project files. Just compiled it for both Release and Debug.

Then, I gave this DLL to another programmer who uses VS 2008 MFC C++. He created a test app to help with testing/debugging DLL's we will be giving him that are written using Qt 4.6.2 with VS2008 C++.

He put the "qtdialog.dll" DLL in his project's local folder and tried both the Debug/Release versions I gave him. He stuck the code for loading/executing the DLL function in a Button handler. He gave me his entire project but the relevant section of code for loading/executing the DLL is shown below.

When the showDialog() function executes, the entire program just crashes with an "Unhandled Exception" error. We can't seem to get around this problem and was wondering if someone here could guide us?

Since my company uses Qt, I need to be able to generate Qt DLL's that a MFC person can load/use in their projects dynamically (no linking of LIBs or DLLs into MFC apps). Is there a better method?? Or, what are we doing wrong here?

Thanks,
Mike H


Here's the code:
void CTestAppDlg::OnBnClickedOk()
{
CString str("qtdialog.dll");
HMODULE mod = LoadLibrary( str );

if ( mod )
{
typedef BOOL(*pShowDialog)(HWND parent);
pShowDialog showDialog = (pShowDialog)GetProcAddress( mod, "showDialog" );
if ( showDialog )
showDialog( theApp.m_pMainWnd->m_hWnd ); //Exception thrown from here.

FreeLibrary( mod );
}
else
{
CAboutDlg aboutDlg;
aboutDlg.DoModal();
}
}