So I have been trying to implement the concept of multithreading to an MFC application I am making. I used the method suggested here. It works fine but I am having an issue with using data given by the user while the thread is working.

I'll explain.

I am making a simple GUI to send and receive data over a serial port. So the data in IDC_SEND is user-input, and is then sent through the serial port. I am using the WINAPI definition of GetDlgItemText, but since the controlling function for AfxBeginThread is defined as a static function I cannot do this. So I tried ::GetDlgItemText, but that calls the CWnd definition which takes one or three or four(?) arguments.

So ::GetDlgItemText(IDC_SEND, CString text) doesn't work. This problem continues for SetDlgItemText too.

I have tried getting the data outside my controlling function, but since it is defined to return a UINT type, I cannot get the received data out.

The relevant code

Code:
void CCommTest2Dlg::OnButton() 
{   
THREADSTRUCT *_param = new THREADSTRUCT;
_param->_this = this;
AfxBeginThread (StartThread, _param);
}


UINT CCommTest2Dlg::StartThread(LPVOID param)
{
THREADSTRUCT*    ts = (THREADSTRUCT*)param;
AfxMessageBox ("Thread is started!");

//Opened Serial Port

//Writing data from Editbox
CString text;

::GetDlgItemText(IDC_SEND,text);//********ERROR HERE!!
serial.Write(text);

//At Receiver port data is wriiten into CString a.

CString a;

::SetDlgItemText( IDC_RECV, a);//Apparently this calls the SetDlgItemText from the CWnd class, and not the Windows API that takes more than one argument.
AfxMessageBox ((LPCTSTR)a);//This works, but I need the data in the EditBox.

//Closing Ports 

delete ts; //Edit 1
return 1;}
A few definitions:

Code:
static UINT StartThread (LPVOID param);

//structure for passing to the controlling function
typedef struct THREADSTRUCT
       {
          CCommTest2Dlg*    _this;

        } THREADSTRUCT;

UINT StartThread(void);
Any thoughts?

PS: Also Edit 1 at the end was added by me as I read that this implementation could result in memory leaks. Does it look like the addition might have fixed that?