On (19 Mar 97) Neil Heller wrote to Jerry Coffin...
JC> For its address to be a normal pointer to a function, the member
JC> has to be static.
NH> The member variable or the member function? Could you please write a
NH> short example for me (us)? Thank you.
The member function. Here's a class I wrote for a vaguely similar
situation a while back:
#define WIN32_LEAN_AND_MEAN
#include
class ThreadBase {
HANDLE handle;
int state_;
DWORD static __stdcall RealThreadProc(void *theClass) {
return ((ThreadBase *)theClass)->ThreadProc();
}
public:
virtual DWORD ThreadProc() = 0;
ThreadBase() {
DWORD ID;
CreateThread(NULL, 0, &RealThreadProc, this, CREATE_SUSPENDED, &ID);
}
int priority() { return GetThreadPriority(handle); }
BOOL priority(int new_priority) {
return SetThreadPriority(handle, new_priority);
}
DWORD run() { return ResumeThread(handle); }
~ThreadBase() { CloseHandle(handle); }
void wait(DWORD how_long) { WaitForSingleObject(handle, how_long); }
// give the caller the thread handle to put in an array
// in a call to [Msg]WaitForMultipleObjects.
HANDLE operator()() { return handle; }
};
This encapsulates a Win32 thread into an object. The thread function
(which gets called by the system, much like the mouse interrupt function
does) is a static member.
Later,
Jerry.
... The Universe is a figment of its own imagination.
--- PPoint 1.90
---------------
* Origin: Point Pointedly Pointless (1:128/166.5)
|