Re: AfxBeginThread
"Bruno van Dooren [MVP VC++]" <bruno_nos_pam_van_dooren@hotmail.com> wrote
in message news:uMywn2CrGHA.4988@TK2MSFTNGP04.phx.gbl...
Is there any automatic way to have AfxBeginThread or some other thread
creation function call a class's member function directly?
I don't see how the "this" pointer would get there.
Typically, the thread function is a static function, which takes an
instance pointer as its input argument.
When starting the thread, you supply AfxBeginThread with the static
function as thread function, and the pointer to your instance as the
thread function argument.
Calling member functions of a specific instance directly is not possible.
This is because thread procedures must be declared stdcall (typically shown
in the documentation as the WINAPI CALLBACK macros), and instance member
functions can't be stdcall. Even though the compiler treats the this
pointer as a hidden first parameter, the different calling conventions
guarantee incompatibility. For example, on x86, the this pointer is passed
in the ECX register, while thread procedures receive an argument on the
stack.
--
Kind regards,
Bruno van Dooren
bruno_nos_pam_van_dooren@hotmail.com
Remove only "_nos_pam"