CWinThread messing itself up
I've been have some trouble lately with a CWinThread. Here's my original declaration:
where StartCryptoPortThread is:
PortThread= AfxBeginThread(StartCryptoPortThread, &Port,THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);
and Port is an instance of a class. Now, the first time that I use PortThread like so:
UINT C_Control::StartCryptoPortThread( LPVOID pParam )
int size = 0;
C_RS_422_Port* pObject = ( C_RS_422_Port*)pParam;
if (pObject == NULL )
return 1; // if pObject is not valid
pObject->Send_Crypto_Key(1); // do something with 'pObject'
return 0; // thread completed successfully
Everything works fine and the program and the GUI continue to run. However, upon using it a second time like so:
I get a ridiculous return of 4 million or something. And then, when pointing to ResumeThread() as previously used (when it worked), it returns the same value of 4 million+. I've been able to discern that sometime after the initial point to ResumeThread(), PortThread goes bad and I get values of 0x00000000 for m_hThread where there used to be an address like 0x0000fd4c and I get 0xfeababab for things like m_pMainWnd/m_pActiveWnd where they used to be 0x00000000. Please help me! I've never actually had to use threads before and I don't know how they work!