Use of callback function in a C++ class of a ActiveX control 
Author Message
 Use of callback function in a C++ class of a ActiveX control

I need to declare a callbackfunction in a C++ class. I will pass that
function to a windows function. When the callback is called - then I must
fire an event called FireMessage to notify the container.

Problem:
I can seem to get the address of the callbackfunction in the class.

Thomas - www.inova.dk



Fri, 28 Jun 2002 03:00:00 GMT  
 Use of callback function in a C++ class of a ActiveX control


Quote:
> I need to declare a callbackfunction in a C++ class. I will pass that
> function to a windows function. When the callback is called - then I must
> fire an event called FireMessage to notify the container.

> Problem:
> I can seem to get the address of the callbackfunction in the class.

Exactly.  Ordinary member functions in objects have an
implied "this" argument that tells them which instance of
the class they should apply to.  You have some choices:

- Make the callback a static member.  This has the drawback
  that it can't see non-static member data.
- Tell the calling function about the specific instance and have
   it somehow connect up to that instance and call the specific
   member function.  You might need to re-write the calling func.
- Pass the calling function a pointer to the specific instance and
  have it call a static member function "cover" of the non-static
  member, passing along the pointer to the instance.  The static
  member then calls the non-static member through the pointer.
  Many library routines that need callbacks allow you to have
  an extra argument that gets passed in this fashion.

There are probably other ways to arrange this.

If you have complete control over the code that calls the callback,
then you have the option of rewriting it.  You could have it take
a pointer to a specific type of object.  For example, you could
make an abstract base class that has the specific interface
members you require.  Then everything that is going to be used
as a callback handler would inherit from that.  And your calling
routines would call it through that interface.

--
Dan Evens
Standard disclaimers etc. No spam please.
Two possible strategies if your boss is a jerk.
1) Polish up your resume and send it to headhunters.
2) Polish up *his* resume and send it to headhunters.



Fri, 28 Jun 2002 03:00:00 GMT  
 Use of callback function in a C++ class of a ActiveX control
Thanks for understanding my question - I was a little worried that I was
totally ununderstandable.

Sorry - I don't have access to the code that calls the callback. The
function is

SetSystemHookEx

I am developing a control that wraps SetSystemHookEx.

Please help me with this matter if you can I am stuck!

Regards Thomas - www.inova.dk


Quote:


> > I need to declare a callbackfunction in a C++ class. I will pass that
> > function to a windows function. When the callback is called - then I
must
> > fire an event called FireMessage to notify the container.

> > Problem:
> > I can seem to get the address of the callbackfunction in the class.

> Exactly.  Ordinary member functions in objects have an
> implied "this" argument that tells them which instance of
> the class they should apply to.  You have some choices:

> - Make the callback a static member.  This has the drawback
>   that it can't see non-static member data.
> - Tell the calling function about the specific instance and have
>    it somehow connect up to that instance and call the specific
>    member function.  You might need to re-write the calling func.
> - Pass the calling function a pointer to the specific instance and
>   have it call a static member function "cover" of the non-static
>   member, passing along the pointer to the instance.  The static
>   member then calls the non-static member through the pointer.
>   Many library routines that need callbacks allow you to have
>   an extra argument that gets passed in this fashion.

> There are probably other ways to arrange this.

> If you have complete control over the code that calls the callback,
> then you have the option of rewriting it.  You could have it take
> a pointer to a specific type of object.  For example, you could
> make an abstract base class that has the specific interface
> members you require.  Then everything that is going to be used
> as a callback handler would inherit from that.  And your calling
> routines would call it through that interface.

> --
> Dan Evens
> Standard disclaimers etc. No spam please.
> Two possible strategies if your boss is a jerk.
> 1) Polish up your resume and send it to headhunters.
> 2) Polish up *his* resume and send it to headhunters.



Fri, 28 Jun 2002 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Passing C++ Class Member Function to as a C Callback Function Parameter

2. How to use member function of a C++ class as a callback function

3. How can I use print callback function of View class using Modal Dialog

4. Using a C++ member function as a Timer callback

5. Using a C++ member function as a Timer callback

6. ATL C++ control using MapPoint ActiveX control

7. Class creating another class and needing callback function

8. class member function as callback function

9. Using Non-Static Callback Functions as member Functions VC5.0

10. Calling C++ member function through C function callback

11. Key/tab problems using VB ActiveX controls in MFC CView and derived classes or PropertyPage

12. Using CScrollView class in ActiveX control

 

 
Powered by phpBB® Forum Software