0

I'm trying migrate a VC++ 6 based code to work with VS2015 CLR. I have major functionality working, but UI has some things missing.

I have traced this issue to failures of SubclassDlgItem due to NULL HWnd for parent CWnd. It is NULL, because Create on a CDialog derived parent class returns 0 at following in dlgcore.cpp

if (hWnd != NULL && !(m_nFlags & WF_CONTINUEMODAL))
    {
        ::DestroyWindow(hWnd);
        hWnd = NULL;
    }

m_nFlags = 256 (Defined as #define WF_OLECTLCONTAINER 0x0100 // some descendant is an OLE control in afxwin.h)

And hWnd is not NULL, but '::CreateDialogIndirect() did NOT create the window (ie. due to error in template) and returns NULL' as per Microsoft comments

Following is the code for parent CWnd

CreateEx(
            WS_EX_NOPARENTNOTIFY,
            NULL,
            "MainClient",
            WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN | WS_CLIPSIBLINGS,
            0, 0,       // Locate at upper left corner of client area
            1, 1,       // Initial size doesn't matter - will be sized to fit parent
            parent->GetSafeHwnd(),
            NULL
        );

Following is the code for CDialog creation

m_pMainDialog = new CxMainDialog();
m_pMainDialog->Create(IDD_MAIN_DIALOG, this);

Below is the CxMainDialog constructor

CxMainDialog::CxMainDialog(CWnd* pParent /*=NULL*/)
    : CDialog(CxMainDialog::IDD, pParent)
{

    //{{AFX_DATA_INIT(CxMainDialog)
        // NOTE: the ClassWizard will add member initialization here
    //}}AFX_DATA_INIT
}

How may I get this to work?

Chaitanya
  • 41
  • 5
  • Thanks, updated 'feel' with specifics. – Chaitanya Jan 04 '17 at 09:01
  • Clarification: MFC comes with sources, you can step into them and check what exactly fails *during creation*. – Werner Henze Jan 04 '17 at 09:03
  • Yes, DestroyWindow is being called inside dlgcore.cpp, because m_nFlags = 256. – Chaitanya Jan 04 '17 at 09:09
  • Did you check creation of the parent window? You did not pass a class name to CreateEx, so that probably fails. When using MFC and even if you don't want to check for errors during release please check them at debug (e.g. by using `VERIFY` macro: `VERIFY(CreateEx(...)`). – Werner Henze Jan 04 '17 at 09:14
  • I have checked it manually before, passes and has a valid HWnd. – Chaitanya Jan 04 '17 at 09:18
  • Please check http://stackoverflow.com/questions/1666927/cwndcreatedlgindirect-leaves-m-hwnd-null – Werner Henze Jan 04 '17 at 10:42
  • Thanks, let me try this and get back here. – Chaitanya Jan 04 '17 at 10:44
  • Suggestion from that question did not work, now I have deleted all the controls from my dialog and while creating an empty dialog, now OnInitDialog is being called and fails at HRSRC hDlgInit = ::FindResource(hInst, lpszResourceName, RT_DLGINIT); with hDlgInit = NULL – Chaitanya Jan 05 '17 at 07:22
  • Thanks @WernerHenze, this issue has been resolved. – Chaitanya Jan 05 '17 at 08:29

1 Answers1

1

This was resolved by fixing the dialog template by removing ActiveX controls causing the problem while Create. I created a duplicate dialog and emptied it to test that Create is successful.

Chaitanya
  • 41
  • 5