RE: [Dev-C++] Static members for callbacks
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Ioannis V. <no...@ho...> - 2002-07-29 07:42:38
|
> -----Original Message-----
> From: Ioannis Vranos [mailto:no...@ho...]
> Sent: Monday, July 29, 2002 10:34 AM
> To: 'Abhijit Shylanath'
> Cc: 'Dev-C++ Mailing List'
> Subject: RE: [Dev-C++] Static members for callbacks
>
>
> > -----Original Message-----
> > From: Abhijit Shylanath [mailto:mu...@gm...]
> > Sent: Monday, July 29, 2002 9:50 AM
> > To: Ioannis Vranos
> > Cc: Dev-C++ Mailing List
> > Subject: Re: [Dev-C++] Static members for callbacks
> >
> >
> > > > You can't use non-static methods for windows callbacks (like in
> > > > CreateThread(), SetWindowsHookEx()) which need you to suppply
> > > > a call-back
> > > > function.
> > >
> > >
> > > This is too Win32 to me. What do you mean by call-back
> > function. Can you
> > > provide a small concrete example?
> >
> >
> > Basically, typedef function_pointer call_back;
> >
> > For example, in CreateThread(), the args are:
> >
> > HANDLE CreateThread(
> > LPSECURITY_ATTRIBUTES lpThreadAttributes, // address of
> > thread security
> > attributes
> > DWORD dwStackSize, // initial thread stack size, in bytes
> > LPTHREAD_START_ROUTINE lpStartAddress, // address of
> > thread function
> > LPVOID lpParameter, // argument for new thread
> > DWORD dwCreationFlags, // creation flags
> > LPDWORD lpThreadId // address of returned thread identifier
> > );
> >
> > Here, LPTHREAD_START_ROUTINE should be a function pointer
> to a 32-bit
> > returning (void *) accepting function, as in
> >
> > DWORD my_thread_proc(void *some_arg);
> >
> > where DWORD is, on Win32, unsigned long.
>
>
>
> Ok then you can use a regular function to call the
> appropriate member function. This regular function will
> accept also your object as a parameter.
In general use an additional regular function. For example if your
function must have a specific return type and specific arguments like:
int s(void *);
You can use a third function *& a global variable e.g.
// The value of the data member of class A
int x;
inline void loadvalue(const A &a)
{
x=a.getvalue();
}
// s now can read the global variable x
Of course this way sucks. But this is not a C++ problem, but Win32
problem which after all is C (or perhaps even pre-ANSI C).
In C there is some use of global variables like errno, although the use
of global variables is not recommended there too.
Ioannis
* Ioannis Vranos
* Programming pages: http://www.noicys.cjb.net
* Alternative URL: http://run.to/noicys
|