Hello,
I've been have some trouble lately with a CWinThread. Here's my original declaration:
Code:
PortThread[3]= AfxBeginThread(StartCryptoPortThread, &Port[3],THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);
where StartCryptoPortThread is:
Code:
UINT C_Control::StartCryptoPortThread( LPVOID pParam )
{
char* buffer;
int size = 0;
C_RS_422_Port* pObject = ( C_RS_422_Port*)pParam;
if (pObject == NULL )
return 1; // if pObject is not valid
else
{
//C_Control::GetOutboundMessage(buffer,size);
pObject->Send_Crypto_Key(1); // do something with 'pObject'
return 0; // thread completed successfully
}
}
and Port[3] is an instance of a class. Now, the first time that I use PortThread[3] like so:
Code:
SuspendCount=PortThread[PortNumber-1]->ResumeThread();
Everything works fine and the program and the GUI continue to run. However, upon using it a second time like so:
Code:
SuspendCount=PortThread[PortNumber-1]->SuspendThread();
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!