I've created a very simple one-button MFC dialog app that attempts to utilize a callback function. The app complies and runs just fine, but the callback routine never gets triggered.
What needs to be modified in order to get the callback to trigger properly?
You can download the test.zip file here (the test app is in VS 2003 to ensure more people can try it out): http://tinyurl.com/testfile-zip
The code utilizes an alarm class on CodeProject, and the callback function is suppsed to get triggered every 3 seconds (as determined by the code being passed in).
Thanks!
-
It helps if you boil down your question to the smallest code that demonstrates the problem.
-
I've looked at your code and the I believe the Function called from the button is the problem
void CTestDlg::OnBnClickedButton1() { CAlarmClock clock; REPEAT_PARMS rp; ZeroMemory(&rp, sizeof(REPEAT_PARMS)); rp.bRepeatForever = TRUE; rp.Type = Repeat_Interval; rp.ss = 3; clock.SetRepeatAlarm(0, 0, 0, rp, CallbackRtn); }
This creates the Alarm clock on the function stack. This CAlarmclock object is therefore destroyed at the end of the function along with its contents.
For it to be able to exist for long enough to actually do the callback you need to add it as a member variable of your dialog class for it to exist and callback for as long as the dialog exists.
See the example code on the CAlarmclock codeproject page for how to use this class correctly.
NotJarvis : I tested putting CALarmcloco clock as a member of the class using the OPs code and it worked straight away.
0 comments:
Post a Comment