Banfa, thank you very much for your quick response. Unfortunately my automatic notification settings must be incorrect, and I didn't notice your response until this morning.
The automatic notification on this site is somewhat broken, I suggest you check back to the site itself every now and then and check your user control panel for updates.
What I ended up doing was creating a non-member function to use as the callback, and calling member functions in the callback using a global pointer to "this".
- VOID timer1Event()
-
{
-
dialogObject->memberFunction(); //dialogObject is a pointer to the form object
-
}
-
I know global variables aren't exactly the best programming practice, but eventually I'll need several different timers each with a different callback function, and this was the easiest way that I could think of to do it.
OK, that is definately the quick and dirty hack :D and you have the prototype of timer1Event wrong, it is supposed to accept an int parameter. This hack will not scale.
Here is what I would say is a better solution
You need a way to associate the LRTimer instance with the CTestDlg instance. Do you access to the code of both classes?
If so then pass a pointer to your CTestDlg instance to the LRTimer, the callback can then be a member function of CTestDlg which LRTimer can call directly, but you would have to handle the case of the CTestDlg instance being deleted before the LRTimer instance had timed out (i.e. the risk of LRTimer trying to use an invalid CTestDlg instance).
If you do not have access to both classes, particularly access to the LRTimer class then:
Firstly make the callback a static member of CTestDlg, if possible make it private. This will only be possible if you create the timer from within the CTestDlg class somewhere.
To associate the 2 instances you will need to have identifying data, this could be the pointer to the class or it could be an id, whatever it is it must uniquely identify the instance. You can then set up a map (again a private member of CTestDlg) which you will be able to consult to get the correct CTestDlg instance for any LRTimer callback and so call the correct object.
When instances are deleted you can simple remove the corresponding map member to prevent use of invalid pointers.