Loading ...
Sorry, an error occurred while loading the content.

Mixing MFC CDialog with WTL

Expand Messages
  • Ron de los Santos
    I m working on a project for Windows Mobile that was created using WTL. But I have to add some preexisting dialogs from another project. The dialogs are
    Message 1 of 2 , Nov 1, 2006
    • 0 Attachment
      I'm working on a project for Windows Mobile that was created using
      WTL. But I have to add some preexisting dialogs from another project.
      The dialogs are CDialogs made with MFC.

      I read a good article, http://www.codeproject.com/wtl/mix_wtl_mfc.asp
      , which has helped me compile using the two sets of libraries by
      basically not automatically using the WTL namespace. However, when I
      run the program I cannot seem to get the dialog to appear.
      dlg.DoModal() fails. Here's a look at some of the code. CAboutDlg is
      a subclass of CDialog.

      CWnd* win = CWnd::FromHandle(m_view.m_hWnd);
      CAboutDlg dlg(win);
      dlg.DoModal();

      I tried again in another project and I got a runtime error doing
      something similar. I believe AfxGetResourceHandle() failed somewhere
      because the app was not an instance of CWinApp. I'm starting to think
      mixing MFC and WTL isn't a very good idea and I should start thinking
      about converting everything to WTL.

      Any help? Thanks a lot.
    • Anna-Jayne Metcalfe
      Hi Ron, ... In order to get this to work, at the very least MFC will need valid CWinApp and mainframe objects, so you will need to make some mods to your core
      Message 2 of 2 , Nov 1, 2006
      • 0 Attachment
        Hi Ron,

        > I tried again in another project and I got a runtime error doing
        > something similar. I believe AfxGetResourceHandle() failed somewhere
        > because the app was not an instance of CWinApp. I'm starting to think
        > mixing MFC and WTL isn't a very good idea and I should start thinking
        > about converting everything to WTL.

        In order to get this to work, at the very least MFC will need valid CWinApp
        and mainframe objects, so you will need to make some mods to your core
        project to accommodate them. For what it's worth, I've found it far easier
        to add WTL code to an MFC project than the other way around. It's generally
        pretty easy to convert MFC windowing/dialog code to WTL anyway.


        Kind Regards,

        Anna-Jayne Metcalfe

        Software/Product Development Consultant,
        Riverblade Limited.

        http://www.riverblade.co.uk
      Your message has been successfully submitted and would be delivered to recipients shortly.