The title is pretty weak, but I will try to explain here. I am working on an MFC Application. When a button is clicked, a new dialog is created, some strings are added to a ComboBox from that second dialog, and then the dialog is showed. The code is depicted below. Combo1 is a CComboBox variable defined in the Class1.h file. The problem is that when I try to call the dlg.Foo() method, the program gives me a Debug Assertion Error. The error hits on the AddString line, furthermore in the afxwin2.inl file, in this line of code:
{ ASSERT(::IsWindow(m_hWnd)); return (int)::SendMessage(m_hWnd, CB_ADDSTRING, 0, (LPARAM)lpszString); }
CClass1 dlg = new CClass1(this);
dlg.Foo();
dlg.DoModal();
void CClass1::Foo()
{
Combo1.AddString(TEXT("text"));
}
You can add the strings to the combo box inside of OnInitDialog(), which gets called automatically during DoModal():
In the header:
In the cpp file: