• Advertisement
Sign in to follow this  

Dam compiler is teaching me what to do!!!

This topic is 4263 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?!

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
is it a static function?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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()

Share this post


Link to post
Share on other sites
Use a static function to pass it off to the non-static one:

class CClass
{
public:
// Normal methods

private:
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);


Share this post


Link to post
Share on other sites
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)

Share this post


Link to post
Share on other sites
Evil Steve's implementation allows you to wrap threads in objects. We've called the initial __stdcall thread a "thread bounce" function around here.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement