Search code examples
c++visual-studio-2010mfccwnd

CWnd::OnCreate function never get called


Overview:
I have 2 utilities and both have same common interface i.e. open a dialog box to "request for username".
The code for "requesting username" is written in different library and both these utilities call that library .

ISSUE:

In 1 utility it works fine and I got this this dialog box which request username but in other utility it doesn't come up.

MY Investigation: ON deeper investigation I found that both these utilities call CDialog::DoModal() which in turns call onCreate() . In my other utility breakpoint never hits onCreate function . Any idea why ?

sample code

// IN actual Utility
//somewhere in code 

Dialog_for_common_interface dlg( message.c_str(), "Please enter username:" );

        CString username;

        bool is_correct = ( dlg.DoModal(username) == IDOK )

// IN Dialog_for_common_interface

int  Dialog_for_common_interface::DoModal ( CString &_reply_c )
{
    int result_i = CDialog::DoModal(); // break point hits this but value of result_i = -1;

    if ( result_i == IDOK )
    {
        _reply_c = reply_c;
    }

    return result_i;
}

// Breakpoint nver hits the below function

int Dialog_for_common_interface::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
    if (CDialog::OnCreate(lpCreateStruct) == -1)
        return -1;

    SetWindowText( title_c );

    return 0;
}

Solution

  • Copy the dialog resource into both exe projects. And make sure they both use the same ID value for the dialog resource.