Click here to Skip to main content
15,918,742 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Timer Callback Pin
ivor bigun6-Aug-03 1:08
ivor bigun6-Aug-03 1:08 
GeneralRe: Timer Callback Pin
Ryan Binns6-Aug-03 1:11
Ryan Binns6-Aug-03 1:11 
GeneralRe: Timer Callback Pin
ivor bigun6-Aug-03 1:31
ivor bigun6-Aug-03 1:31 
GeneralRe: Timer Callback Pin
Phil Speller6-Aug-03 1:53
Phil Speller6-Aug-03 1:53 
GeneralRe: Timer Callback Pin
LittleYellowBird6-Aug-03 2:09
LittleYellowBird6-Aug-03 2:09 
GeneralRe: Timer Callback Pin
LittleYellowBird6-Aug-03 2:12
LittleYellowBird6-Aug-03 2:12 
GeneralRe: Timer Callback Pin
Ryan Binns6-Aug-03 2:19
Ryan Binns6-Aug-03 2:19 
GeneralRe: Timer Callback Pin
Phil Speller6-Aug-03 3:04
Phil Speller6-Aug-03 3:04 
Declaring a member function of class as static will remove the need for an instance of the class to be associated with it - i.e. no this pointer. What this means is that it can't access any of the normal member functions/variables - precisely because there is no associated this pointer. However, supply the static function with a pointer to an instance of the class and you can access all functions/variables (even private ones) via that pointer - because the static function is still declared in the scope of the class.

In terms of pointers to functions, because a static member function has no associated this pointer you can obtain it's address directly (just like a C function) - this is why Ryan's suggestion worked. Any normal member function must have an associated this pointer with it, so even when you take the address of a member function you must still use it with a pointer to an instance of the class as well.

class CMyClass<br />
{<br />
public:<br />
  void MyFn (void);<br />
  static void MyStaticFn (CMyClass *);<br />
};<br />
<br />
typedef void(* FnPtr)(CMyClass*);  // C style fn pointer<br />
typedef void(CMyClass::* MemberFnPtr)();  // C++ style fn pointer<br />
<br />
CMyClass* pMyClass = new CMyClass;<br />
<br />
MemberFnPtr pMFn = &CMyClass::MyFn;<br />
pMyClass->MyFn();           // Calling as normal<br />
pMyClass->*pMFn();          // Calling via pointer to member fn<br />
<br />
FnPtr pFn = &CMyClass::MyStaticFn;<br />
(*pFn)( pMyClass );         // Calling static member fn



[edit]
You could try using the nIDEvent parameter of SetTimer to hold the pointer to your class instance - cast it back to the correct type and use within your static fn.
[/edit]

Hope this helps,


Phil
GeneralRe: Timer Callback Pin
Vitali Halershtein6-Aug-03 2:49
Vitali Halershtein6-Aug-03 2:49 
GeneralRe: Timer Callback Pin
Ryan Binns6-Aug-03 4:19
Ryan Binns6-Aug-03 4:19 
GeneralReselect on combo box OnDropdown Pin
paulccc5-Aug-03 23:58
paulccc5-Aug-03 23:58 
GeneralRe: Reselect on combo box OnDropdown Pin
HPSI6-Aug-03 2:44
HPSI6-Aug-03 2:44 
QuestionPrinting How? Pin
wow99995-Aug-03 23:42
wow99995-Aug-03 23:42 
AnswerRe: Printing How? Pin
HPSI6-Aug-03 2:21
HPSI6-Aug-03 2:21 
Generalvfw depression Pin
mr pier5-Aug-03 23:37
mr pier5-Aug-03 23:37 
GeneralRe: vfw depression Pin
HPSI6-Aug-03 1:48
HPSI6-Aug-03 1:48 
GeneralRe: vfw depression Pin
Anonymous8-Aug-03 8:52
Anonymous8-Aug-03 8:52 
GeneralWebbrowser::Newwindow() Problem!! Pin
xxhimanshu5-Aug-03 23:22
xxhimanshu5-Aug-03 23:22 
Generalopening documents Pin
BoudewijnEctor5-Aug-03 23:14
BoudewijnEctor5-Aug-03 23:14 
GeneralRe: opening documents Pin
HPSI5-Aug-03 23:29
HPSI5-Aug-03 23:29 
QuestionopenDirectory dialog? Pin
BoudewijnEctor5-Aug-03 23:10
BoudewijnEctor5-Aug-03 23:10 
AnswerRe: openDirectory dialog? Pin
Toni785-Aug-03 23:17
Toni785-Aug-03 23:17 
GeneralRe: openDirectory dialog? Pin
BoudewijnEctor5-Aug-03 23:58
BoudewijnEctor5-Aug-03 23:58 
GeneralRe: openDirectory dialog? Pin
David Crow6-Aug-03 5:23
David Crow6-Aug-03 5:23 
AnswerRe: openDirectory dialog? Pin
Chao Zuo5-Aug-03 23:39
Chao Zuo5-Aug-03 23:39 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.