Accessing non-static functions from a static function 
Author Message
 Accessing non-static functions from a static function

After getting the SetTimer() and TimerProc() callback working in my
Dialog based App I realized I don't know how to access a non-static
member function from the static member function that the TimerProc()
is part of!.
I have looked through the MSDN and found that most of the examples
deal with SDI apps and they also place the timer routine in  CWinApp.
I am using it in CDialog for the timer and the examples don't work for
this class (at least not at my technical level).

My main question(s) would be :
- How do I access a non-static member function from a static member
function in a CDialog Class?, the called function returns nothing.

- Or how do I access a public user created function from one class to
another. i.e. I have a self-created function in a CDialog class that I
want to call from a CWinApp class, both are part of the the same
project.

And yes I am using MFC...

THANKS!



Fri, 28 Sep 2001 03:00:00 GMT  
 Accessing non-static functions from a static function
Have you tried passing in a NULL for the callback function parameter in
SetTimer and then handling the WM_TIMER message?  Then you can call the
functions as you would normally...

Hope this helps,
Chris

Quote:

> After getting the SetTimer() and TimerProc() callback working in my
> Dialog based App I realized I don't know how to access a non-static
> member function from the static member function that the TimerProc()
> is part of!.
> I have looked through the MSDN and found that most of the examples
> deal with SDI apps and they also place the timer routine in  CWinApp.
> I am using it in CDialog for the timer and the examples don't work for
> this class (at least not at my technical level).

> My main question(s) would be :
> - How do I access a non-static member function from a static member
> function in a CDialog Class?, the called function returns nothing.

> - Or how do I access a public user created function from one class to
> another. i.e. I have a self-created function in a CDialog class that I
> want to call from a CWinApp class, both are part of the the same
> project.

> And yes I am using MFC...

> THANKS!



Fri, 28 Sep 2001 03:00:00 GMT  
 Accessing non-static functions from a static function

Quote:
>My main question(s) would be :
>- How do I access a non-static member function from a static member
>function in a CDialog Class?, the called function returns nothing.

You can't. That's why using a static member function for a callback is
often worthless, and you may as well use a global function.

Quote:
>- Or how do I access a public user created function from one class to
>another. i.e. I have a self-created function in a CDialog class that I
>want to call from a CWinApp class, both are part of the the same
>project.

If I understand you correctly, you have a public member function in
your CDialog derived class, and want to call it from a member of your
CWinApp derived class. There should be no problem - provided that your
CWinApp has an instance of your CDialog class in order to call the
function.

Dave
----
My address is altered to discourage junk mail.
Please post responses to the newsgroup thread,
there's no need for follow-up email copies.



Thu, 04 Oct 2001 03:00:00 GMT  
 Accessing non-static functions from a static function
Whatt'a people can't read !!!!   He's telling you, in English, that he's
trying to access a non-static member method from a static non-member
function.  That's his question.

David, I am having a similar problem.  I have found an article that resolves
this issue but it does not seem to work for me.  Check it out for yourself
in the MSDN CD's, the article title is "Calling All Members: Member
Functions as Callbacks".

Let me know if you get it to figured out........good luck.

Quote:

>>My main question(s) would be :
>>- How do I access a non-static member function from a static member
>>function in a CDialog Class?, the called function returns nothing.

>You can't. That's why using a static member function for a callback is
>often worthless, and you may as well use a global function.

>>- Or how do I access a public user created function from one class to
>>another. i.e. I have a self-created function in a CDialog class that I
>>want to call from a CWinApp class, both are part of the the same
>>project.

>If I understand you correctly, you have a public member function in
>your CDialog derived class, and want to call it from a member of your
>CWinApp derived class. There should be no problem - provided that your
>CWinApp has an instance of your CDialog class in order to call the
>function.

>Dave
>----
>My address is altered to discourage junk mail.
>Please post responses to the newsgroup thread,
>there's no need for follow-up email copies.



Tue, 23 Oct 2001 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. One Problem in Calling Static function from Non static function

2. Pointers to non-static vs static functions

3. Static array containing non static objects and functions

4. static functions and non static variables

5. static functions with non-static variables!

6. Getting pointer to non-static member function from C callback function

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

8. strange problem occur while trying to access member function through static function

9. static function access member variable and member function

10. Giving static member functions access to protected functions

11. Opinion wanted: Proper naming of non-static functions?

12. static functions broken in non-Unix compilers?

 

 
Powered by phpBB® Forum Software