Click here to Skip to main content
15,893,663 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Notifiation Messages for CSpinButtonCtrl in MFC Pin
Sampath57922-Mar-18 17:17
Sampath57922-Mar-18 17:17 
GeneralRe: Notifiation Messages for CSpinButtonCtrl in MFC Pin
Victor Nijegorodov22-Mar-18 21:52
Victor Nijegorodov22-Mar-18 21:52 
GeneralRe: Notifiation Messages for CSpinButtonCtrl in MFC Pin
Sampath57923-Mar-18 0:22
Sampath57923-Mar-18 0:22 
GeneralRe: Notifiation Messages for CSpinButtonCtrl in MFC Pin
Jochen Arndt22-Mar-18 22:00
professionalJochen Arndt22-Mar-18 22:00 
GeneralRe: Notifiation Messages for CSpinButtonCtrl in MFC Pin
Sampath57923-Mar-18 0:22
Sampath57923-Mar-18 0:22 
AnswerRe: Notifiation Messages for CSpinButtonCtrl in MFC Pin
Victor Nijegorodov22-Mar-18 4:38
Victor Nijegorodov22-Mar-18 4:38 
QuestionQR CODE IN ARABIC Pin
Member 1054250021-Mar-18 6:13
Member 1054250021-Mar-18 6:13 
AnswerRe: QR CODE IN ARABIC Pin
Richard MacCutchan21-Mar-18 6:44
mveRichard MacCutchan21-Mar-18 6:44 
GeneralRe: QR CODE IN ARABIC Pin
Member 1054250021-Mar-18 6:59
Member 1054250021-Mar-18 6:59 
GeneralRe: QR CODE IN ARABIC Pin
leon de boer21-Mar-18 16:44
leon de boer21-Mar-18 16:44 
AnswerRe: QR CODE IN ARABIC Pin
Daniel Pfeffer21-Mar-18 9:37
professionalDaniel Pfeffer21-Mar-18 9:37 
GeneralRe: QR CODE IN ARABIC Pin
Member 1054250021-Mar-18 11:13
Member 1054250021-Mar-18 11:13 
GeneralRe: QR CODE IN ARABIC Pin
leon de boer21-Mar-18 16:35
leon de boer21-Mar-18 16:35 
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 

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.