Article View: borland.public.cppbuilder.nativeapi
Article #3704Re: TimeSetEvent
From: Remy Lebeau (TeamB)
Date: Fri, 28 Apr 2006 16:58
Date: Fri, 28 Apr 2006 16:58
48 lines
2573 bytes
2573 bytes
"David Dean" <ozchzhq02@sneakemail.com> wrote in message
news:ozchzhq02-9725F7.12284128042006@frylock.local...
> The error produced by the compiler is:
You are trying to use a non-static class method as the callback. You cannot
do that (not directly, anyway). Such a method requires a 'this' pointer be
passed to it when called. TimeSetEvent() does not know how to do that. It
expects a standalone function as the callback. In order to use a class
method, you must declare it as 'static'. The only downside is that the
callback will no longer be able to access non-static members of the class,
since no 'this' pointer is available. Fortunately, TimeSetEvent() allows
you to specify your own 32-bit value in the dwUser parameter, and that value
will be passed to the callback. So you can pass the class's 'this' pointer
in that parameter. For example:
class myClass
{
private:
int value; // <-- for deomstration only
static void CALLBACK OneShotTimer(UINT wTimerID, UINT msg, DWORD
dwUser, DWORD dw1, DWORD dw2);
public:
void send(const AnsiString &outString, int delay, unsigned short
timeout);
};
void myClass::send(const AnsiString &outString, int delay, unsigned
short timeout)
{
//...
value = 0;
timeSetEvent(timeout, 100, &OneShotTimer,
reinterpret_cast<DWORD>(this), TIME_ONESHOT);
}
void CALLBACK myClass::OneShotTimer(UINT wTimerID, UINT msg, DWORD
dwUser, DWORD dw1, DWORD dw2)
{
myClass *pThis = reinterpret_cast<myClass*>(dwUser);
// use pThis as needed ...
pThis->value = 1;
}
Gambit
Technical Details
Message-ID:
<44524b44$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news2.google.com!news2.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<ozchzhq02-9725F7.12284128042006@frylock.local>Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,7550567434949799 X-Google-Attributes: gid10cc67,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Remy Lebeau \(TeamB\)" <no.spam@no.spam.com> Newsgroups: borland.public.cppbuilder.nativeapi References: <ozchzhq02-9725F7.12284128042006@frylock.local> Subject: Re: TimeSetEvent Date: Fri, 28 Apr 2006 09:58:42 -0700 Lines: 50 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1409 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409 NNTP-Posting-Host: 68.69.17.41 Message-ID: <44524b44$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1146243908 68.69.17.41 (28 Apr 2006 10:05:08 -0700) Path: arc1-ca.pugleaf.net!g2news2.google.com!news2.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail