• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

C/C++ Cwnd timer

What am I doing wrong? it compiles but I get an exception when I try to run. The exception is as follows:

Debug assertation failed
File: afwwin1.inl
Line: 21

When I run the app in debug mode, it sems like the call to:
this->CreateEx(0, WC_STATIC, 0, 0, 0, 0, 0, 0, HWND_MESSAGE, 0);
is what is causing the exception.

The code is as follows:

------------- header file (Foo.h):

#include <afxmt.h>
#include <afxwin.h>

class Foo : public CWnd

{
public:
Foo();

afx_msg void OnTimer(UINT nIDEvent);


DECLARE_MESSAGE_MAP()
};

------------- cpp file (Foo.cpp)

#include "Foo.h"

BEGIN_MESSAGE_MAP(Foo, CWnd)
//{{AFX_MSG_MAP(Foo)
ON_WM_TIMER()
//}}AFX_MSG_MAP
END_MESSAGE_MAP( )

Foo::Foo() {

// used 'this->' to make sure that the CWnd method is called and not the C funtion

this->CreateEx(0, WC_STATIC, 0, 0, 0, 0, 0, 0, HWND_MESSAGE, 0);

timerID = SetTimer(1, 500, NULL);
}

void Foo:: OnTimer(UINT nIDEvent)
{
// <code here>
;
CWnd:: OnTimer(nIDEvent);
}

 
Just a guess:
OnTimer is declared as return type afx_msg void, but implemented as void.

You may also want to check your SetTimer return value to see if an error is thrown.
 
Is your Foo object a global? Most of MFC won't work until after its initialization code is run.

I don't know if initialization is done in the CWinApp constructor or in WinMain, but in either case you won't be able to reliably use static objects. One fix would be to make it a pointer and initialize it in InitInstance.
 
Back
Top