none
mfc dialog dll with embedded windows form

    Question

  • I am trying to use windows forms in an mfc application. I got the integration to work in various configurations, so this is not a basic question.

     

    I am building a dll (I tried both regular and extension) with a MFC dialog and a windows form embedded in it. When the dialog is initialized from the main MFC diver application it fails in the assertion below.

     

    If the MFC dialog wrapper is moved out of the dll into the main app, things work fine. If the dialog is used in the dll, as in the integration example in MSDN, things work fine too. In my case I create the MFC dialog in the dll and use it in the main app from a menu command.

     

    I am not well versed in OLE, just want to use windows forms, so please be gentle with me. I am using C++ everywhere.

     

    Roman

     

     

    CCmdTarget::~CCmdTarget()

    {

    #ifndef _AFX_NO_OLE_SUPPORT

    if (m_xDispatch.m_vtbl != 0)

    ((COleDispatchImpl*)&m_xDispatch)->Disconnect();

    >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>   ASSERT(m_dwRef <= 1);

    #endif

    m_pModuleState = NULL;

    }

     

    Here's the trace (ColorPicker below has nothing to do with the system provided dialog):

     

    > mfc80ud.dll!CCmdTarget::~CCmdTarget()  Line 43 + 0x19 bytes C++
      mfc80ud.dll!COleControlSite::~COleControlSite()  Line 128 + 0x33 bytes C++
      [Managed to Native Transition] 
      mfcm80ud.dll!Microsoft::VisualC::MFC::CWinFormsControlSite::~CWinFormsControlSite() Line 381 + 0x2a bytes C++
      mfcm80ud.dll!<Module>.Microsoft.VisualC.MFC.CWinFormsControlSite.__vecDelDtor(uint  = 1) + 0x55 bytes 
      [Native to Managed Transition] 
      mfc80ud.dll!COleControlContainer::CreateControlCommon(CWnd * pWndCtrl=0x01244c04, const _GUID & clsid={...}, const CControlCreationInfo & creationInfo={...}, const wchar_t * lpszWindowName=0x00000000, unsigned long dwStyle=268435456, const tagPOINT * ppt=0x0012e840, const tagSIZE * psize=0x0012e848, unsigned int nID=1234, CFile * pPersist=0x00000000, int bStorage=0, wchar_t * bstrLicKey=0x00000000, COleControlSite * * ppNewSite=0x00000000)  Line 348 + 0x21 bytes C++
      mfc80ud.dll!COleControlContainer::CreateControl(CWnd * pWndCtrl=0x01244c04, const CControlCreationInfo & creationInfo={...}, unsigned long dwStyle=268435456, const tagPOINT * ppt=0x0012e840, const tagSIZE * psize=0x0012e848, unsigned int nID=1234)  Line 294 C++
      mfc80ud.dll!CWnd::CreateControl(const CControlCreationInfo & creationInfo={...}, unsigned long dwStyle=268435456, const tagPOINT * ppt=0x0012e840, const tagSIZE * psize=0x0012e848, CWnd * pParentWnd=0x01244b90, unsigned int nID=1234)  Line 92 C++
      [Managed to Native Transition] 
      ColorPickerDll.dll!Microsoft::VisualC::MFC::CWinFormsControl<ColorPickerDll::ColorPicker2>::InternalCreateManagedControl(CControlCreationInfo& info = {...}, unsigned int dwStyle = 268435456, tagRECT& rect = {...}, CWnd* pParentWnd = 0x01244B90, int nID = 1234) Line 122 + 0x1c bytes C++
      ColorPickerDll.dll!Microsoft::VisualC::MFC::CWinFormsControl<ColorPickerDll::ColorPicker2>::CreateManagedControl(unsigned int dwStyle = 268435456, tagRECT& rect = {...}, CWnd* pParentWnd = 0x01244B90, int nID = 1234) Line 149 + 0x63 bytes C++
      ColorPickerDll.dll!CArColorDialog:SurprisenInitDialog() Line 59 + 0x1d bytes C++
      [Native to Managed Transition] 
      mfc80ud.dll!AfxDlgProc(HWND__ * hWnd=0x001107b4, unsigned int message=272, unsigned int __formal=985008, unsigned int __formal=985008)  Line 28 + 0x10 bytes C++
      user32.dll!7739b6e3()  
      [Frames below may be incorrect and/or missing, no symbols loaded for user32.dll] 
      user32.dll!77395f82()  
      user32.dll!77395f38()  
      user32.dll!77395e22()  
      ntdll.dll!7c831a1f()  
      user32.dll!77395ffa()  
      user32.dll!7739b6e3()  
      user32.dll!7739b874()  
      user32.dll!7739b82a()  
      ntdll.dll!7c838bf3()  
      user32.dll!7739bfce()  
      user32.dll!7739bf74()  
      mfc80ud.dll!CWnd:Big SmileefWindowProcW(unsigned int nMsg=272, unsigned int wParam=985008, long lParam=0)  Line 1029 + 0x20 bytes C++
      mfc80ud.dll!CWnd:Big Smileefault()  Line 274 C++
      mfc80ud.dll!CDialog::HandleInitDialog(unsigned int __formal=985008, unsigned int __formal=985008)  Line 633 + 0x8 bytes C++
      mfc80ud.dll!CWnd:SurprisenWndMsg(unsigned int message=272, unsigned int wParam=985008, long lParam=0, long * pResult=0x0012efd8)  Line 2004 + 0x11 bytes C++
      mfc80ud.dll!CWnd::WindowProc(unsigned int message=272, unsigned int wParam=985008, long lParam=0)  Line 1741 + 0x20 bytes C++
      mfc80ud.dll!AfxCallWndProc(CWnd * pWnd=0x01244b90, HWND__ * hWnd=0x001107b4, unsigned int nMsg=272, unsigned int wParam=985008, long lParam=0)  Line 240 + 0x1c bytes C++
      mfc80ud.dll!AfxWndProc(HWND__ * hWnd=0x001107b4, unsigned int nMsg=272, unsigned int wParam=985008, long lParam=0)  Line 389 C++
      ColorPickerDll.dll!AfxWndProcDllStatic(HWND__ * hWnd=0x001107b4, unsigned int nMsg=272, unsigned int wParam=985008, long lParam=0)  Line 73 + 0x15 bytes C++
      user32.dll!7739b6e3()  
      user32.dll!7739b874()  
      user32.dll!7739b82a()  
      user32.dll!7739c2d3()  
      user32.dll!77388c01()  
      mfc80ud.dll!ATL::CSimpleStringT<wchar_t,1>::Attach(ATL::CStringData * pData=0x10000000)  Line 788 + 0x8 bytes C++
      user32.dll!77387910()  
      user32.dll!7739fb5b()  
      mfc80ud.dll!CWnd::CreateDlgIndirect(const DLGTEMPLATE * lpDialogTemplate=0x100300e8, CWnd * pParentWnd=0x0124358c, HINSTANCE__ * hInst=0x10000000)  Line 307 + 0x2a bytes C++
      mfc80ud.dll!CDialog::CreateIndirect(const DLGTEMPLATE * lpDialogTemplate=0x100300e8, CWnd * pParentWnd=0x0124358c, void * lpDialogInit=0x00000000, HINSTANCE__ * hInst=0x10000000)  Line 211 C++
      mfc80ud.dll!CDialog::CreateIndirect(void * hDialogTemplate=0x100300e8, CWnd * pParentWnd=0x0124358c, HINSTANCE__ * hInst=0x10000000)  Line 188 + 0x16 bytes C++
      mfc80ud.dll!CDialog::Create(const wchar_t * lpszTemplateName=0x00000bb8, CWnd * pParentWnd=0x0124358c)  Line 170 + 0x14 bytes C++
      mfc80ud.dll!CDialog::Create(unsigned int nIDTemplate=3000, CWnd * pParentWnd=0x0124358c)  Line 601 + 0x18 bytes C++
      [Managed to Native Transition] 
      ColorPickerDll.dll!RunModalColorDialog(CWnd* pParent = 0x003FC820) Line 16 + 0x22 bytes C++
      ntdll.dll!7c82709b()  
      [Native to Managed Transition] 
      ArTestDriver.exe!CArTestDriverView:SurprisenToolsChangecolor()  Line 122 + 0x9 bytes C++

     

    Tuesday, October 02, 2007 9:02 PM

All replies

  • Have you added this line:
    Code Block
    AFX_MANAGE_STATE(AfxGetStaticModuleState( ));

     


    to the beginning of the function in which dll dialog is launched? If not, try it.

    Monday, October 08, 2007 11:38 AM
  • This is necessary but not sufficient.

     

    It appears that the CDialog subclass with embedded form has to be defined and used in the same module.

     

    If I define it in the main mfc executable and link in the dll with the form it works. Invoking it accross a dll boundary causes the problem. If there is a magic way to do that I don't know it.

     

    My customer wants a dll exporting plain CDialog which can be used in natively compiled code.

     

     

    Monday, October 08, 2007 8:19 PM
  • Hello, if your version of  Visual Studio is greater than RTM.50727.01, please submit a bug report in http://connect.microsoft.com/visualstudio. Otherwise, try upgrade to latest version.

     

    thanks

    rico

    Tuesday, October 09, 2007 3:14 AM
  • Here's my version. I cannot tell if it's greater then .01

     

    Microsoft Visual Studio 2005
    Version 8.0.50727.42  (RTM.050727-4200)
    Microsoft .NET Framework
    Version 2.0.50727

    Installed Edition: Professional

    Microsoft Visual Basic 2005   77626-009-0353127-41364
    Microsoft Visual Basic 2005

    Microsoft Visual C# 2005   77626-009-0353127-41364
    Microsoft Visual C# 2005

    Microsoft Visual C++ 2005   77626-009-0353127-41364
    Microsoft Visual C++ 2005

    Microsoft Visual J# 2005   77626-009-0353127-41364
    Microsoft Visual J# 2005

    Microsoft Visual Web Developer 2005   77626-009-0353127-41364
    Microsoft Visual Web Developer 2005

    Crystal Reports    AAC60-G0CSA4B-V7000AY
    Crystal Reports for Visual Studio 2005

     

    Tuesday, October 09, 2007 6:55 AM
  • Yes, and I suggest you to submit a bug to the link above. Preferablely, you can create a minimum repro project and attach it to the bug report.

     

    thanks

    rico

    Tuesday, October 09, 2007 7:16 AM