Click to See Complete Forum and Search --> : timeSetTimer Callback Issues
eeboy
January 21st, 2006, 04:52 AM
I have a compilation error I can't figure out. I am calling timeSetTimer from a member function within a class. The callback function is also a member of the class.
When I compile this statement:
timeSetEvent(iDelay, 0, &wait, NULL, TIME_ONESHOT);
I get:
error C2276: '&' : illegal operation on bound member function expression
When I compile this statement:
timeSetEvent(iDelay, 0, &FOO::wait, NULL, TIME_ONESHOT);
I get:
error C2664: 'timeSetEvent' : cannot convert parameter 3 from 'void (__stdcall FOO::*)(unsigned int,unsigned int,unsigned long,unsigned long,unsigned long)' to 'void (__stdcall *)(unsigned
Any ideas?
Thanks!
Andreas Masur
January 21st, 2006, 05:36 AM
How to use class member functions as callbacks? (http://www.codeguru.com/forum/showthread.php?t=312457)
eeboy
January 21st, 2006, 05:46 AM
Makes sense... Thanks!
Andreas Masur
January 21st, 2006, 06:02 AM
You are welcome...
eeboy
January 21st, 2006, 06:10 PM
Ok... I am back with a similar issue. I've decided to place a flag in the callback function that I will clear upon execution. I have the flag as a private member of the class. When I attempt to clear it inside the callback function with:
pulsing=false;
I get:
illegal reference to data member 'FOO::pulsing' in a static member function
The error makes sense because the this pointer is not passed along. I figured declaring the flag as
static bool pulsing;
would solve this issue... but that generates an unresolved external symbol.
Any help?
Andreas Masur
January 21st, 2006, 07:06 PM
You basically have two choices here...
Using a static member. They need to be defined however, thus...
// .hpp
class foo
{
static bool pulsing;
};
// .cpp
bool foo::pulsing = false;
'timeSetEvent()' allows you to pass a user-defined value as a 'DWORD_PTR'. You can use this to pass the 'this' pointer of the class instance you want to access in your callback...
eeboy
January 21st, 2006, 07:33 PM
I ended up using the DWORD dwUser parm to pass the pointer this to the function. I couldn't get your first example to work. I had actually tried that. It doesn't seem to like the static bool pulsing declaration. I still get the unresolved external symbol error.
Even though I have it working I would still like to know why declaring the flag as static doesn't work for me.
Thanks!
Andreas Masur
January 22nd, 2006, 05:29 AM
Even though I have it working I would still like to know why declaring the flag as static doesn't work for me.
Well...without seeing the actual you tried it with, it is pretty hard to tell...nevertheless, it should have worked.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.