Callback functions
-
I'm trying to use the function AVISave, which takes as a parameter a callback function: AVISAVECALLBACK lpfnCallback with the prototype: LONG PASCAL SaveCallback(int nPercent) When it comes to passing a function to another function, we leave the realm of any C++ that I understand. How do I call AVISave? And, where does the "Pascal" come from? thanks, Jake
-
I'm trying to use the function AVISave, which takes as a parameter a callback function: AVISAVECALLBACK lpfnCallback with the prototype: LONG PASCAL SaveCallback(int nPercent) When it comes to passing a function to another function, we leave the realm of any C++ that I understand. How do I call AVISave? And, where does the "Pascal" come from? thanks, Jake
I don't know the prototype for AVISave, but this is the general idea:
LONG PASCAL SaveCallback(int nPercent)
{
UpdateProgress(nPercent);
}void SaveAVIFile()
{
AVISave(SaveCallback, /*the othe parameters here*/);
}So really, in essence, you just treat the function as a variable. Hope that helps, > Andrew.
-
I don't know the prototype for AVISave, but this is the general idea:
LONG PASCAL SaveCallback(int nPercent)
{
UpdateProgress(nPercent);
}void SaveAVIFile()
{
AVISave(SaveCallback, /*the othe parameters here*/);
}So really, in essence, you just treat the function as a variable. Hope that helps, > Andrew.
This is what my code looks like, where AVISave takes a callback function as 3rd arg: long PASCAL CBadClass::SaveCallback(int percent) { return AVIERR_OK; } ... bool CBadClass::Foo() { AVISave(...,SaveCallback, ...); } This gives me the compilation error: error C2664: 'AVISaveA' : cannot convert parameter 3 from 'long (int)' to 'int (__stdcall *)(int)' None of the functions with this name in scope match the target type needless to say, I've got no ideas here X| thanks, Jake
-
This is what my code looks like, where AVISave takes a callback function as 3rd arg: long PASCAL CBadClass::SaveCallback(int percent) { return AVIERR_OK; } ... bool CBadClass::Foo() { AVISave(...,SaveCallback, ...); } This gives me the compilation error: error C2664: 'AVISaveA' : cannot convert parameter 3 from 'long (int)' to 'int (__stdcall *)(int)' None of the functions with this name in scope match the target type needless to say, I've got no ideas here X| thanks, Jake
Your question is answered in the VC forum FAQ. See http://www.codeproject.com/useritems/cppforumfaq.asp#cpp_callbacks --Mike-- http://home.inreach.com/mdunn/ "Make sure that if you are using a blow torch that you don't set anything on fire." -- Chris Maunder
-
Your question is answered in the VC forum FAQ. See http://www.codeproject.com/useritems/cppforumfaq.asp#cpp_callbacks --Mike-- http://home.inreach.com/mdunn/ "Make sure that if you are using a blow torch that you don't set anything on fire." -- Chris Maunder
The ForumFAQ article has tons of good stuff, including telling me to make my callback function global or static, however I've tried it with each and still get the exact same error as before (see previous message). X| So, something else is killing me, I guess...any more ideas? thanks, Jake
-
This is what my code looks like, where AVISave takes a callback function as 3rd arg: long PASCAL CBadClass::SaveCallback(int percent) { return AVIERR_OK; } ... bool CBadClass::Foo() { AVISave(...,SaveCallback, ...); } This gives me the compilation error: error C2664: 'AVISaveA' : cannot convert parameter 3 from 'long (int)' to 'int (__stdcall *)(int)' None of the functions with this name in scope match the target type needless to say, I've got no ideas here X| thanks, Jake
Well, for starters the parameter is a pointer to the callback function, so you might try &SaveCallback. Christian Secrets of a happy marriage #27: Never go to bed if you are mad at each other. It's more fun to stay up and fight.
-
The ForumFAQ article has tons of good stuff, including telling me to make my callback function global or static, however I've tried it with each and still get the exact same error as before (see previous message). X| So, something else is killing me, I guess...any more ideas? thanks, Jake
Your member function doesn't have the required prototype. It's
long PASCAL CBadClass::SaveCallback(int percent)
but AVISAVECALLBACK is defined as
typedef BOOL (FAR PASCAL * AVISAVECALLBACK)(int);
Change the return type of your function to BOOL. And BTW, FAR is obsolete and can be ignored, and PASCAL has been replaced by CALLBACK in Win32. --Mike-- http://home.inreach.com/mdunn/ "Make sure that if you are using a blow torch that you don't set anything on fire." -- Chris Maunder