I'm trying to launch a modal dialog from a DLL loaded by an MFC application. I'm using VS2010 and both the EXE and DLL use MFC in a static library.
I call DoModal()
in my DLL to launch the dialog, with the parent being a CWnd* pointing to the main window from the MFC app. The dialog resource is in the DLL.
This eventually leads to the MFC library function CWnd::CreateDlgIndirect
, which has this debug check:
#ifdef _DEBUG
if ( AfxGetApp()->IsKindOf( RUNTIME_CLASS( COleControlModule ) ) )
{
TRACE(traceAppMsg, 0, "Warning: Creating dialog from within a COleControlModule application is not a supported scenario.\n");
}
#endif
AfxGetApp()
returns NULL so the code in the debug check fails. If I compile in release, the dialog appears, but doesn't seem to work (all the fields are empty even though I set defaults, some button's don't appear).
I've tried adding AFX_MANAGE_STATE(AfxGetStaticModuleState());
to the top of the function that launches the dialog, and it doesn't make any difference.
What am I missing?
Edit: here's the code I use to call the dialog.
HMODULE oldResMod = AfxGetResourceHandle();
AFX_MANAGE_STATE(AfxGetStaticModuleState());
AfxSetResourceHandle(GetThisModule());
CWnd wndParent;
wndParent.Attach(parent);
CExportOptionsDlg dlg(&wndParent);
dlg.project_name = project->GetName();
if (dlg.DoModal() != IDOK)
{
wndParent.Detach();
AfxSetResourceHandle(oldResMod);
return false; // cancelled
}
// ... (get some data from the dialog members) ...
wndParent.Detach();
AfxSetResourceHandle(oldResMod);
return true; // OK
CreateIndirect
is for modeless dialogs? You probably wantInitModalIndirect
before callingDoModal
but it would be helpful to show YOUR code. The problem is not likely in the MFC debug assert but rather a bug in usage causing the assert to fail. - AJG85