Advertisement

Darn MFC/assertion errors

Started by June 29, 2001 11:05 PM
3 comments, last by Verso 23 years, 7 months ago
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)
Remember - Hard work pays off in the long run, but laziness pays off immediately.
What exception are you getting?

Use Debug and find the line that is causing the exception and post the code for the function that it is in.
Advertisement
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.
"Just remember, hard work pays off in the long run, but laziness always pays off now."
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?
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

This topic is closed to new replies.

Advertisement