In my application I launch a thread with AfxBeginThread. The data I want to pass to this thread is a pointer to the owner and the command line of the owner process.

My header file for the thread process looks like:


UINT RunTribes(LPVOID pParam);

typedef struct _THREAD_DATA {
CWnd* pParent;
LPTSTR cCmdLine;
} THREAD_DATA, *PTHREAD_DATA;




In my parent process I create and set the parameters of a variable, then launch the thread. Like so:


PTHREAD_DATA pParamData;

pParamData->pParent = this;
pParamData->cCmdLine = GetCommandLine();
AfxBeginThread(RunTribes, pParamData);




My actual thread looks like this:


UINT RunTribes(LPVOID pParam)
{
PTHREAD_DATA pThreadData = (PTHREAD_DATA) pParam;
char *szCmdLine = "tribes.exe ";
LPTHREADINFO pThreadInfo = new THREADINFO;
CEvent *pThreadEvent = new CEvent(FALSE, TRUE);

strcat(szCmdLine, pThreadData->cCmdLine);

ASSERT_VALID(pThreadEvent);
if(pThreadInfo)
{
pThreadInfo->pTermThreadEvent = pThreadEvent;
pThreadInfo->strPathName = szCmdLine;

AfxBeginThread(LaunchAndWait, pThreadInfo);
WaitForSingleObject(pThreadEvent->m_hObject, INFINITE);
}
pThreadData->pParent->PostMessage(WM_CLOSE, 0, 0L);

AfxEndThread(0);
return 0;
}




The problem is I get an access violation in my parent process when setting the "this" property. Can someone help me on this?

I have successfully passed the parent pointer without the typedef(I didn't have command line data), but I don't know how I pass both of them to the process.