Click here to Skip to main content
15,886,919 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: QR CODE IN ARABIC Pin
Daniel Pfeffer21-Mar-18 20:24
professionalDaniel Pfeffer21-Mar-18 20:24 
QuestionWinTECH opc client Pin
D.Manivelan20-Mar-18 21:28
D.Manivelan20-Mar-18 21:28 
AnswerRe: WinTECH opc client Pin
Victor Nijegorodov20-Mar-18 22:26
Victor Nijegorodov20-Mar-18 22:26 
AnswerRe: WinTECH opc client Pin
Richard MacCutchan20-Mar-18 22:43
mveRichard MacCutchan20-Mar-18 22:43 
Questionporting _beginthreadex from VS2005 to VS2017 Pin
jimNLX20-Mar-18 5:13
jimNLX20-Mar-18 5:13 
AnswerRe: porting _beginthreadex from VS2005 to VS2017 Pin
Jochen Arndt20-Mar-18 5:43
professionalJochen Arndt20-Mar-18 5:43 
GeneralRe: porting _beginthreadex from VS2005 to VS2017 Pin
jimNLX6-Apr-18 9:03
jimNLX6-Apr-18 9:03 
AnswerRe: porting _beginthreadex from VS2005 to VS2017 Pin
leon de boer20-Mar-18 8:00
leon de boer20-Mar-18 8:00 
You are calling a class member function you must shim it thru a static function
C++
#include <process.h>  
class foo
{
public:
	void startTheThread()
	{
		// Start the thread for the sendData (we send "this" in as a parameter for shim)
        // The shim code is a static block for all your class instances hence &foo::sendData 
        // It creates a class member call from the value of "this" passed in 
		sendHandle = _beginthreadex(0, 0, &foo::sendData, this, 0, &this->m_sendThreadId);
	}
private:
	void sendDataMemberCall()
	{
		/* All the real send code goes here */
	}

	static unsigned __stdcall sendData(void *p_this)
	{
		/* This is just a shim to convert a thread call to a member function call */
		foo* p_foo = static_cast<foo*>(p_this);
		p_foo->sendDataMemberCall(); // call Non-static member function!
		return 0;
	}
	uintptr_t sendHandle;
	unsigned m_sendThreadId;
};

As a quick explaination a non static class function has a hidden invisible pointer which you know as "this".
So if you look at the member function sendDataMemberCall it looks like this to you
void sendDataMemberCall()

At a code level it actually looks like this
void sendDataMemberCall (foo* this);

The compiler pushes down a hidden pointer to the actual instance of the class object
So if we had two instances foo1 and foo2 when you call sendDataMemberCall they actually do this
sendDataMemberCall (&foo1);
sendDataMemberCall (&foo2);

So the problem is the format we need for the thread function doesn't match the class function and we can't
make them match because of the hidden local instance push. However the thread function does allow us to pass
a parameter and we pass "this" as a parameter. So now what you can do is typecast this back to a pointer to
it's type and get the compiler to call the pointer member function and it will magically push our hidden pointer.

So all the shim is really doing is turning function + extra parameter into push paramater call class function.
In vino veritas


modified 20-Mar-18 20:50pm.

GeneralRe: porting _beginthreadex from VS2005 to VS2017 Pin
jimNLX6-Apr-18 9:06
jimNLX6-Apr-18 9:06 
GeneralRe: porting _beginthreadex from VS2005 to VS2017 Pin
jimNLX11-Apr-18 9:03
jimNLX11-Apr-18 9:03 
GeneralRe: porting _beginthreadex from VS2005 to VS2017 Pin
leon de boer17-Apr-18 21:45
leon de boer17-Apr-18 21:45 
GeneralRe: porting _beginthreadex from VS2005 to VS2017 Pin
jimNLX18-Apr-18 3:49
jimNLX18-Apr-18 3:49 
GeneralRe: porting _beginthreadex from VS2005 to VS2017 Pin
leon de boer18-Apr-18 15:27
leon de boer18-Apr-18 15:27 
GeneralRe: porting _beginthreadex from VS2005 to VS2017 Pin
jimNLX9-May-18 9:18
jimNLX9-May-18 9:18 
GeneralRe: porting _beginthreadex from VS2005 to VS2017 Pin
leon de boer9-May-18 16:11
leon de boer9-May-18 16:11 
GeneralRe: porting _beginthreadex from VS2005 to VS2017 Pin
jimNLX11-May-18 6:23
jimNLX11-May-18 6:23 
QuestionOpenCL bit-matrix multiplication (implementing tiling in local memory) Pin
User 1370349219-Mar-18 19:19
User 1370349219-Mar-18 19:19 
AnswerRe: OpenCL bit-matrix multiplication (implementing tiling in local memory) Pin
leon de boer19-Mar-18 23:47
leon de boer19-Mar-18 23:47 
GeneralRe: OpenCL bit-matrix multiplication (implementing tiling in local memory) Pin
User 1370349220-Mar-18 1:02
User 1370349220-Mar-18 1:02 
GeneralRe: OpenCL bit-matrix multiplication (implementing tiling in local memory) Pin
leon de boer20-Mar-18 3:12
leon de boer20-Mar-18 3:12 
GeneralRe: OpenCL bit-matrix multiplication (implementing tiling in local memory) Pin
User 1370349220-Mar-18 10:09
User 1370349220-Mar-18 10:09 
GeneralRe: OpenCL bit-matrix multiplication (implementing tiling in local memory) Pin
leon de boer20-Mar-18 15:27
leon de boer20-Mar-18 15:27 
GeneralRe: OpenCL bit-matrix multiplication (implementing tiling in local memory) Pin
User 1370349221-Mar-18 3:50
User 1370349221-Mar-18 3:50 
GeneralRe: OpenCL bit-matrix multiplication (implementing tiling in local memory) Pin
leon de boer21-Mar-18 4:25
leon de boer21-Mar-18 4:25 
GeneralRe: OpenCL bit-matrix multiplication (implementing tiling in local memory) Pin
User 1370349221-Mar-18 7:00
User 1370349221-Mar-18 7:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.