Dam compiler is teaching me what to do!!!

Started by
7 comments, last by Verg 17 years, 11 months ago
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?!
______________________________Madman
Advertisement
is it a static function?
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.
I am shocked, it isnt possible to pass a non static class method to create thread?
It's all about the wheel.Never blindly trust technoligy.I love my internal organs.Real men don't shower.Quote:Original post by Toolmaker Quote:Original post by The C modest godHow is my improoved signature?It sucks, just like you.
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)
"We confess our little faults to persuade people that we have no large ones." -Francois de La Rochefoucauld (1613 - 1680). | My blog
I honestly can't believe how often this gets asked around here :(
Evil Steve's implementation allows you to wrap threads in objects. We've called the initial __stdcall thread a "thread bounce" function around here.
my_life:          nop          jmp my_life
[ Keep track of your TDD cycle using "The Death Star" ] [ Verge Video Editor Support Forums ] [ Principles of Verg-o-nomics ] [ "t00t-orials" ]

This topic is closed to new replies.

Advertisement