Remy Lebeau (TeamB) wrote:
Quote
>I get this compiler error which I don't understand:
>[C++ Error] MMMTimer.cpp(53): E2231 Member TMMMTimer::FOnMMMTimerEvent
>cannot be used without an object
The event is not a static member of the class. You must use a pointer to a
real object instance in order to access the event. Since you appear to be
passing the component's 'this' pointer as a user-defined value to the timer,
then you can use that ponter to reach the event, ie:
void CALLBACK TMyComponent::TimerEvent(UINT ID, UINT D1, DWORD dwUser,
DWORD dw1, DWORD dw2)
{
TMyComponent *pThis = reinterpret_cast<TMyComponent*>(dwUser);
if( pThis->FOnMMMTimerEvent )
pThis->FOnMMMTimerEvent(pThis);
}
Thanks Remy, yes I am trying to pass the compnent's 'this' pointer ...
and here is how I'm trying to do it (with the changes you suggested).
But I get a compiler error:
[C++ Error] MMMTimer.cpp(54): E2247 'TMMMTimer::FOnMMMTimerEvent' is not
accessible
TimerEvent is not declared. If I declare it:
private:
void CALLBACK TimerEvent(UINT ID, UINT D1, DWORD dwUser, DWORD D2,
DWORD D3);
//---------------------------------------------------------------------------
void __fastcall TMMMTimer::StartTimer(void)
{
DWORD dwUser = reinterpret_cast<DWORD>(this);
ID = timeSetEvent(ThisPeriod, FResolution, TimerEvent, dwUser, Mode);
}
//---------------------------------------------------------------------------
void CALLBACK TimerEvent(UINT ID, UINT D1, DWORD dwUser, DWORD D2, DWORD D3)
{
TMMMTimer *pThis = reinterpret_cast<TMMMTimer*>(dwUser);
if( pThis->FOnMMMTimerEvent ) // compiler error
pThis->FOnMMMTimerEvent(pThis); // compiler error
}
TimerEvent is not declared. If I declare it:
private:
void CALLBACK TimerEvent(UINT ID, UINT D1, DWORD dwUser, DWORD D2,
DWORD D3);
and
//---------------------------------------------------------------------------
void CALLBACK TMMMTimer::TimerEvent(UINT ID, UINT D1, DWORD dwUser,
DWORD D2, DWORD D3)
{
TMMMTimer *pThis = reinterpret_cast<TMMMTimer*>(dwUser);
if( pThis->FOnMMMTimerEvent ) // compiler error
pThis->FOnMMMTimerEvent(pThis); // compiler error
}
//---------------------------------------------------------------------------
void __fastcall TMMMTimer::StartTimer(void)
{
DWORD dwUser = reinterpret_cast<DWORD>(this); // error next line
ID = timeSetEvent(ThisPeriod, FResolution, TimerEvent, dwUser, Mode);
}
//---------------------------------------------------------------------------
Then I get complier errors:
[C++ Error] MMMTimer.cpp(68): E2034 Cannot convert 'void (__stdcall *
(_closure )(unsigned int,unsigned int,unsigned long,unsigned
long,unsigned long))(unsigned int,unsigned int,unsigned long,unsigned
long,unsigned long)' to 'void (__stdcall *)(unsigned int,unsigned
int,unsigned long,unsigned long,unsigned long)'
and
[C++ Error] MMMTimer.cpp(68): E2342 Type mismatch in parameter 'fptc'
(wanted 'void (__stdcall *)(unsigned int,unsigned int,unsigned
long,unsigned long,unsigned long)', got 'void')
Nate
{smallsort}