VC ++ general error 21: Debug assertion failed! Error in winocc. cpp 307th or 329 rows

Source: Internet
Author: User

From: http://hi.baidu.com/vc_net/item/a6357e0e6d5437f3a1103447

Incorrect assertions,


Find the code (this version is vs2010, and each version will be different. It may not be in line 329th, but it all means this), as shown below:

Bool cwnd: showwindow (INT ncmdshow)
{
Assert (: iswindow (m_hwnd) | (m_pctrlsite! = NULL); // This is the 329 line of vs2010. The error is returned here.

If (m_pctrlsite = NULL)
Return: showwindow (m_hwnd, ncmdshow );
Else
Return m_pctrlsite-> showwindow (ncmdshow );
}

Error Cause Analysis:

Find out the cause of the Error. Let's take a look at how the code is written. How can this happen?


Void ckgdlg: onbnclickedstatusbtn ()
{
If (home_stata _)
{
M_html_home.movewindow (33,107,660,466 );
M_html_home.showwindow (sw_show );

//: Movewindow (m_html_home.m_hwnd, 33,107,660,466, 1 );
//: Showwindow (m_html_home.m_hwnd, sw_show );

Home_stata _ = false;
}
Else
{
M_html_home.movewindow (33,107,660, 66 );
M_html_home.showwindow (sw_hide );

//: Movewindow (m_html_home.m_hwnd, 33,107,660 );
//: Showwindow (m_html_home.m_hwnd, sw_hide );

Home_stata _ = true;
}
}

Solution:

Void ckgdlg: onbnclickedstatusbtn ()
{
If (home_stata _)
{
// M_html_home.movewindow (33,107,660,466 );
// M_html_home.showwindow (sw_show );

: Movewindow (m_html_home.m_hwnd, 33,107,660,466, 1 );
: Showwindow (m_html_home.m_hwnd, sw_show );

Home_stata _ = false;
}
Else
{
// M_html_home.movewindow (33,107,660, 66 );
// M_html_home.showwindow (sw_hide );

: Movewindow (m_html_home.m_hwnd, 33,107,660, 66,1 );
: Showwindow (m_html_home.m_hwnd, sw_hide );

Home_stata _ = true;
}
}

Why? It is because MFC is used,

Why? Because the API is used.

The real reason is that the handle passed in by the API is the handle of the control, that is, the control-> m_hwnd, And the handle passed in by MFC is the handle of this class (that is, ckgdlg class, that is, this-> m_hwnd.

Another thing to note is that the release version may run normally sometimes, so you are lucky to use it. In fact, both the release version and the debug version must be handled in the above way, if you want to control a control, you can upload the corresponding handle.

Assertion reference: http://hi.baidu.com/vc_net/item/82e10f0c4a1e776dd55a113f

Thanks to the original creators...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.