Hello, I need help about this thing. For shure this have been seen many times but I just can't find the keywords to search about....:P Here is the problem:
I have a CDialog derived window with a "privExecCommand( CHAR cmd )" function that I placed in the class. Now, I started a worker thread (without GUI ) to receive commands from serial port. This thread the wants to send the commands to the main window calling that function. Let's say:
Now, it happens that pCaller is really the pointer to the main object, because some functions that do not access to the members but just draw on the GUI, do work. Else, when I call the "privExecCommand( cmd )" function, the fields of the called object are....new, empy, different from the real object.Code:class CMyDlg : public CDialog { .... private: void privExecCommand( CHAR cmd ); static INT privListeningThread( LPVOID pParams ); .... } BOOL CMyDlg::OnInitDialog() { .... AfxBeginThread( (AFX_THREADPROC) privListeningThread, (LPVOID)(this) ); .... } INT CMyDlg::privListeningThread(LPVOID pParams) { .... CMyDlg *pCaller = (CMyDlg*) pParams; .... pCaller->privExecCommand( cmd ); }
Why does this happen? Thank you for any hint.