Re: Can't do a cast (from my own class to a global scope function)
"David Lowndes" <DavidL@example.invalid>
???????:dlncp2lgm1h4r92h2tfs5oimbi4ksse30r@4ax.com...
Your class method would need to be a static method (otherwise it has
an invisible "this" parameter) - which generally means that it may as
well be a global function anyway.
The usual way of passing a class instance to a thread is to pass a
pointer to the class via the thread pointer parameter and cast it
appropriately in the thread function.
Thanks Dava for the reply.
I still don't quite get it.
Can you raise an example?
I haven't done thread programming before
Jack,
Have a global thread function:
And use _beginthreadex to call it, passing a pointer to the class
instance. In this example I pass "this" on the assumption that this
code is inside a method of the appropriate class:
_beginthreadex( NULL, 0, MyThreadFn, this, 0, &ThreadNr );
Hi Dave,
Do all threads pass thru the ThreadFn marshalling point?
Say I have 2 objects I want to animate... say a soldier and a foe, each
carrying its own thread.
Do I do this?
_beginthreadex(NULL, 0, MyThreadFn, soldierproc,0, &ThreadNr);
and
_beginthreadex(NULL, 0, MyThreadFn, foeproc, 0, &ThreadNr);
Then I'm stuck... How do you seperate the 2 threads?
unsigned __stdcall MyThreadFn(void* pTArg)
{
/* Cast the pointer to your class */
CMyClass * pMyClass = (CMyClass *) pTArg;
pMyClass->PublicMethod();
...
}
Do I do somethin' like this?
pMyClass->Render();
?????????????
Dave