The debugger should have shown you the text of the assertion that failed, maybe something like "hWnd == NULL" or whatever. That information is needed to provide help on the specific assertion.
Also, you can break into the assertion code itself and examine the stack to see just where you called a library function that asserted. Then you can enter that routine and see the arguments you used. Again, this will give some clues as to why the library function didn't like your call.
Unfortunately screenshots are not easy to do in these forums so you'll have to type in the information. Once you have done that, I or others can offer more concrete suggestions on fixing the problem.
-------
I see your updated question. When you hit retry to debug, it should have taken you directly to the assert statement where the test being made is clear.
I'm assuming there's a lot more code than you've shown. Structurally, you're T::Myfunc() function instantiated an object of class A, which includes an instantion of the CListBox object. However, as Solution 2 points out, "instantiating" a ClistBox object is not the same as "Creating a visible window that is a ListBox". The object needs to be "connected" to the actual Windows object that is on the screen. Until that is the case, you cannot do any manipulation on the object. You can check this by using the debugger to examine the content of the 'm_listvalue' object and look at the inner 'CWnd' object. If it is not initialized, then your object has not been connected to the real visible control and this will give you these problems.
This connection between local object instantiation and the real Windows Control is called sub-classing and is something you have to set up in your application before you can manipulate controls in this manner.
Without seeing more of the code and/or how you defined and instantiated the CDialog that is visible, there's not many suggestions on how to fix it.
-------
Ah, your control is not "subclassed" properly. Here's how you do that:
First, as mentioned in the other solution, you cannot reference m_listbox to manipulate the control until *after* the OnInitDialog() member of your Dialog class has been called. It is not until then that the actual screen GUI elements are created.
Second, you need to declare that you are doing Data Exchange and list the controls that you will be subclassing in the DDX list, as below:
class MyDialogClass : public CDialog
{
virtual void DoDataExchange(CDataExchange* pDX);
}
void MyDialogClass::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_xxxxxx, m_listbox);
}
Where IDC_xxxxxx is the identifier of the actual Windows Control created in your Dialog Editor