Dam compiler is teaching me what to do!!!
I have a function -> unsigned long __stdcall CClass::threadfunc(void *param);
and I want to make a thread with it -> _beginthreadex(NULL, 0, (unsigned long (__stdcall *)(void *))CClass::threadfunc, NULL, 0, &thread_1);
Compiler is sending me for a walk no matter what I do. Dam I hate when you have to dance around some supid checks just to feed 32 bit function adress to a stupid machine!!! Does anyone know what I'm doing wrong?!
There's a big difference between static and non-static functions. Therefore if threadfunc isn't static then it isn't just a 32 bit function address, you need to pass the object to operate on somewhere to.
Member functions are totally different than static or global functions (they have a different calling convention, because they need access to a this pointer). If you want to use a member function like that, you'll need some global wrapper to pass to beginthread()
Use a static function to pass it off to the non-static one:
class CClass{public: // Normal methodsprivate: static unsigned long __stdcall staticthreadfunc(void *param) { return ((CClass*)param)->threadfunc(); } unsigned long threadfunc(); // Implement as normal};// Call it like this:_beginthreadex(NULL, 0, staticthreadfunc, this, 0, &thread_1);
If you think about it it's pretty logical that you can't pass a pointer to a member function since a member-function is useless outside the context of an object.
Use a global a global function as a wrapper instead.
(oh man gamedev is fried right now....getting so many errors)
Use a global a global function as a wrapper instead.
(oh man gamedev is fried right now....getting so many errors)
Evil Steve's implementation allows you to wrap threads in objects. We've called the initial __stdcall thread a "thread bounce" function around here.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement