0
votes

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?

1
Thanks, updated 'feel' with specifics.Chaitanya
Clarification: MFC comes with sources, you can step into them and check what exactly fails during creation.Werner Henze
Yes, DestroyWindow is being called inside dlgcore.cpp, because m_nFlags = 256.Chaitanya
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
I have checked it manually before, passes and has a valid HWnd.Chaitanya

1 Answers

1
votes

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.