TIMERPROC
メンバー関数ポインタをWINAPIで使用するタイプに変換するにはどうすればよいSetTimer
ですか?以下のコードスニペットは、私が現在それをどのように行っているかを示していますが、コンパイルすると、次のエラーが発生します。
エラーC2664:'SetTimer':パラメータ4を'void(__stdcall CBuildAndSend :: *)(HWND、UINT、UINT_PTR、DWORD)'から'TIMERPROC'に変換できません
コールバックは、元のクラスインスタンスに関連付ける必要があります。それを行うためのより良い方法があれば、私はすべての耳です。ありがとう。
class CMyClass
{
public:
void (CALLBACK CBuildAndSend::*TimerCbfn)( HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime );
private:
void CALLBACK TimeoutTimerProc( HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime );
};
CMyClass::CMyClass()
{
...
this->TimerCbfn = &CBuildAndSend::TimeoutTimerProc;
...
::CreateThread(
NULL, // no security attributes
0, // use default initial stack size
reinterpret_cast<LPTHREAD_START_ROUTINE>(BasThreadFn), // function to execute in new thread
this, // thread parameters
0, // use default creation settings
NULL // thread ID is not needed
)
}
void CALLBACK CMyClass::TimeoutTimerProc( HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime )
{
...
}
static DWORD MyThreadFn( LPVOID pParam )
{
CMyClass * pMyClass = (CMyClass *)pParam;
...
::SetTimer( NULL, 0, BAS_DEFAULT_TIMEOUT, pMyClass->TimerCbfn ); // <-- Error Here
...
}