Question

Debug assertion failure in mfc app

Asked by: dhenderson12

I have an mfc dialog application and  I'm not using precompiled headers.  The app compiles in both release and debug configurations and runs fine in release ... I can even step through it using breakpoints.

When I try to run in debug I get the following error as soon as it starts:
Debug assertion failed!
File: f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\wincore.cpp
Line: 329

This occurs when the app tries to open the main dialog modally:       
INT_PTR nResponse = dlg.DoModal();

This was created by the VS2008 mfc app wizard.  Any help appreciated.

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2009-08-30 at 19:43:46ID24693857
Topic

Microsoft Visual C++.Net

Participating Experts
2
Points
500
Comments
27

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Assertion Failure in MFC Dialog Box program
    What would cause an Assertion Failure on the constructor of a CWinApp object? How would one go about solving this problem? (The constructor has no construction code, it was placed in the program by MFC)
  2. MFC debug assertion message
    Hi, I have developed a console app with MFC support in Visual Studio 6. The problem is when I run it in another PC that has visual studio 6 installed, I get the a message "Debug Assertion failed" right away. When I re-compile it on that PC, the program runs fine. ...
  3. Get assertion failure in MFC Dialog-based app
    We have a MFC dialog-based app which also supports COM automation. The MFC wizard which created it placed the following line in the "DlgProxy.cpp" file: ASSERT (AfxGetApp()->m_pMainWnd != NULL); The above line is in the CDlgProxy ctor, which seems to be a cla...
  4. MFC and Shell Assert errors
    I am attempting to write a small dialog based MFC program that uses the SHGetValue to check a registry value. However, whenever I include shlwapi.h and link with shlwapi.lib, the program crashes before it can even get started with the following error: Debug Assertation Fail...
  5. Assertion in MFC
    Hi, I've created a Dialog in VC++ 6.0 and added it to a DLL. My test program is a MFC application that uses this dialog instead of the regular AfxMessageBox. When my dialog's window is destroyed I always get the following assertion: BOOL CWnd::DestroyWindow() { // ... #ifd...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: AndyAinscowPosted on 2009-08-30 at 23:21:05ID: 25220777

When you have the ASSERT firing at the dialog with abort, retry and ignore press retry.  What is the code at line
File: f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\wincore.cpp

 

by: dhenderson12Posted on 2009-08-31 at 17:33:31ID: 25227668

After I get the error, click on Retry, and get a message the my app has triggered a breakpoint ... the breakpoint is on the line in the first message, line 329.

 

by: dhenderson12Posted on 2009-08-31 at 17:53:04ID: 25227742

I neglected to say this, but this project was originally built in VS2003 and then VS2008 converted it.  Sorry if this might have some impact.

 

by: pgnatyukPosted on 2009-08-31 at 22:56:36ID: 25228841

So try to open the dialog form in the resource editor, maybe, even add a button/static text, and fully rebuild the solution.

 

by: AndyAinscowPosted on 2009-08-31 at 23:02:34ID: 25228865

What is the code in the line the error appears on - different versions of MFC may well not have the same code at that line.

 

by: dhenderson12Posted on 2009-09-01 at 18:24:31ID: 25237556

in vs2003 the assertion failure happens on line 330: in vs2008 the assertion failure happens on line 329 ... both in wincore.cpp.  It is the same code which is:
BOOL CWnd::Attach(HWND hWndNew)
{
      ASSERT(m_hWnd == NULL);     // only attach once, detach on destroy
      ***** the above line is where the assertion fails! ***************

                ASSERT(FromHandlePermanent(hWndNew) == NULL);
            // must not already be in permanent map

adding items to the dialog and building the project from scratch (clean then build) doesn't change anything.

 

by: pgnatyukPosted on 2009-09-01 at 21:13:45ID: 25238038

It is in Attach. What are you attaching?
Probably, there are differences between the MFC structures and classes in 2003 and 2005.
You've tried to build the project from scratch in VS2003 and it didn't help.
Precompiled headers - what's wrong with it? MFC applications like it.

 

by: dhenderson12Posted on 2009-09-02 at 17:55:14ID: 25247101

I didn't say anything was wrong with precompiled headers ... I simply said I am not using precompiled headers.  With or without them doesn't help my situation with this error.  

I am not attaching anything specific that I know of.  Everything is MS and I'm not using any 3rd party tools, just what's in the studio.  And it is all fine in release mode.  I'm a novice so I'm not even sure what questions to ask at this point, so don't think I'm being obscure deliberately;  I just don't know where else to look.

 

by: dhenderson12Posted on 2009-09-02 at 18:02:42ID: 25247129

OK, I found the problem. I was subclassing some button controls to add graphics to them.  Once I commented them out of the dialog init routine, the error went away.

So my last post was wrong.  I am using the sxbutton.cpp code I found on the web, I believe at CodeGuru.com, to add some graphics to my buttons.

Thanks to all who responded and sorry for the incorrect post.

 

by: pgnatyukPosted on 2009-09-02 at 21:15:18ID: 25247835

I think this answer ID:25238038 helped to find the problem.

 

by: AndyAinscowPosted on 2009-09-02 at 22:36:12ID: 25248079

>>Once I commented them out of the dialog init routine, the error went away.

I think you will find one (or more) was being subclassed more than once.  Or you added a member variable to one (or more) via the wizard.

All you need to do is just comment out the line where the ID is being used a second time.


ps.  That is why I wanted to know what the code was that asserted - it helps the experts here to find out what was wrong and give a useful suggestion.

 

by: pgnatyukPosted on 2009-09-02 at 23:07:11ID: 25248182

Can be even a simplier errror - the button was created and then attached to another window. Something like:
CButton* pBtn = new CButton;
pBtn->Create(...);
pBtn->Attach(...);

 

by: dhenderson12Posted on 2009-09-05 at 11:05:44ID: 25267150

Here's my response:

The last two comments, 25248079 and 25248182, are totally wrong for this question as they didn't read my closing comment.  The error had nothing to do with those suggestions, in fact, not even close.

While comment 25238038 was interesting, as my closing comment states, I wasn't "attaching" anything, I was subclassing a couple of buttons on the dialog.  The other mention of pre-compiled headers also has nothing to do with it.  

I appreciate the responses and am always generous in awarding points to the respondents.  However, in this case I "stumbled" on the answer myself.  I will leave it to the moderator to award the points the best way he or she sees fair without argument.

 

by: AndyAinscowPosted on 2009-09-05 at 11:40:37ID: 25267275

>>Here's my response:
The last two comments, 25248079 and 25248182, are totally wrong for this question as they didn't read my closing comment.


Interesting.  My comment (25248079) adresses this sort of error found in subclassing (as stated by the asker in his closing comment).  If a control is subclassed a second time then this ASSERT will be thrown.  A blanket removal of all the subclassing  code (as the asker states he does) will cure the error, but is in fact a complete overkill.  All that is required is to not subclass that control a second time and the functionality (graphics) will still be available.

 

by: pgnatyukPosted on 2009-09-05 at 22:48:44ID: 25268825

dhenderson12: I'm not sure you understatood what was the reason for the assert. SetWindowLongPtr in Win API does not contain any ASSERT. Probably you used SubclassWindow from MFC and the fist line there is the check:
if (!Attach(hWnd))
return FALSE;
So tell us that we were not right.
So if another programmer will look in EE for the same problem, he will find this thread and will think what? Subclassing fails when it is used for the adding some graphic?

 

by: dhenderson12Posted on 2009-09-06 at 08:20:08ID: 25270260

No, I didn't use subclass window.  Here is the offending code:

      m_UserOptions.SubclassDlgItem( IDC_BUTTON_USEROPTIONS, this );
      m_UserOptions.SetIcon( IDI_ICON_PICTURE1, 40, 40);
      m_UserOptions.SetImagePos( CPoint( SXBUTTON_CENTER, 6));
      m_UserOptions.SetTextPos( CPoint( SXBUTTON_CENTER, 42));
      m_UserOptions.EnableWindow(0);

When this is commented out, the assertion failure goes away.

 

by: AndyAinscowPosted on 2009-09-06 at 08:34:03ID: 25270325

OK, some bad code here (kiddies do not do this at home).

void CzDlg::OnBnClickedButton1()
{
   CEdit e, e2;
   e.SubclassDlgItem(IDC_EDIT1, this);
   e2.SubclassDlgItem(IDC_EDIT1, this);
   e.SubclassDlgItem(IDC_EDIT2, this);

First point - SubclassDlgItem calls SubclassWindow in the processing.

e2.SubclassDlgItem(IDC_EDIT1, this);
That line ASSERTS because IDC_EDIT1 is subclassed to variable e.



void CzDlg::OnBnClickedButton1()
{
   CEdit e, e2;
   e.SubclassDlgItem(IDC_EDIT1, this);
//    e2.SubclassDlgItem(IDC_EDIT1, this);
   e.SubclassDlgItem(IDC_EDIT2, this);

e.SubclassDlgItem(IDC_EDIT2, this);
That line ASSERTS because variable e is already assigned to a different control.


If you look at your code I expect you will find that m_UserOptions is already being used to link to another control (either in on of those ways above or using another method  eg. DDX_ type macro)



I guess the following code will work AND DO WHAT YOU WANT WITH THE GRAPHICS (I've not checked it in detail however).
//     m_UserOptions.SubclassDlgItem( IDC_BUTTON_USEROPTIONS, this );
     m_UserOptions.SetIcon( IDI_ICON_PICTURE1, 40, 40);
     m_UserOptions.SetImagePos( CPoint( SXBUTTON_CENTER, 6));
     m_UserOptions.SetTextPos( CPoint( SXBUTTON_CENTER, 42));
     m_UserOptions.EnableWindow(0);

 

by: pgnatyukPosted on 2009-09-06 at 08:44:11ID: 25270363

dhenderson12, please now read your original question - you didn't have any idea what's going on.
Now say that you found and fixed the problem yourself.

 

by: dhenderson12Posted on 2009-09-06 at 09:01:40ID: 25270422

I have a class that enables me to add graphics to a button control;  Why I want the graphics is not part of the discussion or your concern.

I have a standard button control (only one).  To use the graphics on the button I need to subclass the button (the instructions of the sfxbutton class).  This is only done once, not a bunch of times as your made-up example.  I have only one button and one dialog (do you think I'm making this up?).

As far as what others will dicern from the problem I was having and the solution I found for it, that will have to be judged by whether or not they actually READ the solution I posted as to what was happening in my code, not by problems being fabricated to allow the answer to fit the fabrication.

 

by: AndyAinscowPosted on 2009-09-06 at 09:13:02ID: 25270453

>>This is only done once

That is NOT possible - if it was the case then you would not get an ASSERT at the line of code you indicate.

 

by: dhenderson12Posted on 2009-09-06 at 09:22:14ID: 25270486

ok, guys.  you caught me.  I'm lying.  I made the whole thing up.  I'll split the points just because you answered the email.  just let me know what answers you want me to accept as an answer, the ones that don't actually answer a question or the one that give the bogus example code that makes the question fit the answer.

 

by: pgnatyukPosted on 2009-09-06 at 09:27:11ID: 25270503

ID:25220777
:)

 

by: pgnatyukPosted on 2009-09-06 at 09:39:42ID: 25270550

I knew that.

 

by: AndyAinscowPosted on 2009-09-06 at 10:19:10ID: 25270693

>>ok, guys.  you caught me.  I'm lying.

I hope not and actually think you are just p***d off.

I think you have been telling the truth as you know it BUT that it was in fact incorrect due to lack of understanding of MFC and Windows operate.
I think you have not been prepared to accept that other might have been giving good information and advice and rather than saying to yourself 'erm, maybe they know something I don't, I'd better check' you have been just assuming you know better.

If I am correct in my thoughts then a final piece of advice - consider a career change, you aren't likely to hack it as a programmer with such an attitude.

 

by: pgnatyukPosted on 2009-09-07 at 06:52:00ID: 25275060

Thanks.

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...