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.
Main Topics
Browse All TopicsI 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
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.
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.
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.
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.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
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.
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
// 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.
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.
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.
>>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.
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.
>>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.
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?
No, I didn't use subclass window. Here is the offending code:
m_UserOptions.SubclassDlgI
m_UserOptions.SetIcon( IDI_ICON_PICTURE1, 40, 40);
m_UserOptions.SetImagePos(
m_UserOptions.SetTextPos( CPoint( SXBUTTON_CENTER, 42));
m_UserOptions.EnableWindow
When this is commented out, the assertion failure goes away.
OK, some bad code here (kiddies do not do this at home).
void CzDlg::OnBnClickedButton1(
{
CEdit e, e2;
e.SubclassDlgItem(IDC_EDIT
e2.SubclassDlgItem(IDC_EDI
e.SubclassDlgItem(IDC_EDIT
First point - SubclassDlgItem calls SubclassWindow in the processing.
e2.SubclassDlgI
That line ASSERTS because IDC_EDIT1 is subclassed to variable e.
void CzDlg::OnBnClickedButton1(
{
CEdit e, e2;
e.SubclassDlgItem(IDC_EDIT
// e2.SubclassDlgItem(IDC_EDI
e.SubclassDlgItem(IDC_EDIT
e.SubclassDlgItem(IDC_EDIT
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.SubclassDlgI
m_UserOptions.SetIcon( IDI_ICON_PICTURE1, 40, 40);
m_UserOptions.SetImagePos(
m_UserOptions.SetTextPos( CPoint( SXBUTTON_CENTER, 42));
m_UserOptions.EnableWindow
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.
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.
>>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.
Business Accounts
Answer for Membership
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 \atlmfc\sr c\mfc\winc ore.cpp
File: f:\dd\vctools\vc7libs\ship