Dear Karl,
> just due to a problem that I wasnt allowed to call a
> virtual function from a static one.
That has nothing to do with CWinThread specifically. That is part of the C++ specification. A static function by definition has no instance data, therefore no 'this' pointer. Of course having a 'this' pointer is critical to virtual functions.
The common practice for most call back functions is to provide a user data parameter in both the callback and the setup fuction, as in _beginthread. It takes a (void*) parameter which in turn is passed on to the thread function which is defined as:
void( __cdecl *start_address )( void * ),
That parameter is how you pass your 'this' pointer in the case of an object oriented thread class.
class mythread
{
unsigned long _tHandle;
public:
static void __cdecl threadfunc(void* ptr);
virtual int getIntValue(){ return 10; }
void start(){
_tHandle = _beginthread( threadfunc, 0, (void*)this);
}
};
// static callback function
void __cdecl mythread::threadfunc(void* ptr){
// no this pointer so us the 'ptr' parameter to gain access
// to the object instance that is using this callback
mythread* pThis = (mythread*)ptr;
// call virtual function
cout << pThis->getIntValue();
}
Hope this helps
-pete [sig][/sig]