|
debug assertion in vc++ 2008 |
Posted by Mayur on Nov-06-2012 15:11 |
|
HI
when i try to call m_ChartViewer.setChart(c) function my applicatin generate debug asssertion Failed.
void CChartViewer::setChart(BaseChart *c)
{
// In case the user forgets to check the "Notify" check box in the Dialog editor, we set it
// ourselves so the CChartViewer control can receive mouse events.
if ((GetStyle() & SS_NOTIFY) == 0) --in this line generate debug assertion
ModifyStyle(0, SS_NOTIFY);
m_currentChart = c;
setImageMap(0);
if (0 != c)
{
commitPendingSyncAxis(c);
if (m_delayUpdateChart != NO_DELAY)
c->makeChart();
}
updateDisplay();
}
BOOL CWnd::ShowWindow(int nCmdShow)
{
ASSERT(::IsWindow(m_hWnd) || (m_pCtrlSite != NULL));
if (m_pCtrlSite == NULL)
return ::ShowWindow(m_hWnd, nCmdShow);
else
return m_pCtrlSite->ShowWindow(nCmdShow);
} |
Re: debug assertion in vc++ 2008 |
Posted by Peter Kwan on Nov-07-2012 03:02 |
|
Hi Mayur,
Is the assertion about the Windows handle, like:
ASSERT(::IsWindow(m_hWnd) || (m_pCtrlSite != NULL));
The above assertion means that the code have not associated the Windows control to the MFC class. You must create the Windows control and associated it to the MFC class before using the MFC class. This is the same for all MFC classes, not just CChartViewer.
The Windows operating system define certain controls. To use those controls, you need to use the Win32 API. This is difficult, so Microsoft created MFC as "wrappers" to the Windows control . To use the MFC object, you must associated it with the Windows control. In the MFC framework, if your Windows control is defined as a resource (eg. using the Windows dialog editor), the association usually occurs during the OnInitDialog (the OnInitDialog in the MFC framework should call DoDataExchange, which will use DDX_Control to associate the MFC object with the Windows control). Depending on your coding style and the Visual Studio version you are using, these code are sometimes automatically generated by Visual Studio. You may also dynamically create the MFC control using myControl.Create.
So in brief, please check if your code has created the Windows control and associated it with the MFC object. Does your code run after OnInitDialog, or before it? If your code has overridden OnInitDialog, have you called the OnInitDialog of the base class? Have your code use DDX_Control to associate the MFC object with the Windows control?
If the above still does not solve the problem, is it possible to attach a sample project (may be just modify the "HelloWorld" example project) so I may diagnose the problem?
Regards
Peter Kwan |
|