Archived

This topic is now archived and is closed to further replies.

Darn MFC/assertion errors

This topic is 6010 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

All I wanted to do was compile a simple program with a simple menu using MFC. Did it work? Ohhhh, but Noooooooo (Thanks Microsoft for simplifying my windows programming job). It compiles OK, but when I run it, I get an assertion error - (in file afxwin2.inl... if that means anything). Anyone have any ideas? (Hopefully aside from not using MFC)

Share this post


Link to post
Share on other sites
Sitting in for Verso:

Line 168:

{ ASSERT(::IsWindow(m_hWnd)); return ::SetTimer(m_hWnd, nIDEvent, nElapse,
(TIMERPROC)lpfnTimer); }

Just remember, hard work pays off in the long run, but laziness always pays off now.

Share this post


Link to post
Share on other sites
Ha Ha, all you really wanted to do was RTFM for MFC!

To solve your problem, first you need to have a valid window handle (m_hWnd != NULL).

Then, the next questions are, why is your window trying to use a timer? and at what point in the program do you try to start the timer?

Share this post


Link to post
Share on other sites
You're using SetTimer before creating the actual window. If you weren't using MFC, you would get the same error (except windows would do something nasty instead of having an assert condition break your debugger right at the source of the problem)

The best place to set a timer is on the first update if you're using a view or in InitDialog if you're using a dialog.

Also note, you should have really popped up the stack into your own code. Assert doesn't mean there's an error in MFC's code, it means there's an error in your code that MFC was nice enough to catch for you. The debugger jumps to the assert line, but you should jump up the stack into your code to see what the problem was. In your case, it would have been the line in your program that's calling SetTimer.

Edited by - Stoffel on July 1, 2001 2:45:46 PM

Share this post


Link to post
Share on other sites