Yeah, I tried rebuilding and different optimizations and neither worked.
Code:
PortThread[3]= AfxBeginThread(StartCryptoPortThread, &Port[3],THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);
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
}
}
void Crypto_Dlg::OnBnClickedCryptoPortAct()
{
CString sString;
CButton* pButton;
const bool Active = TRUE;
pButton = (CButton*)GetDlgItem(IDC_Crypto_Port_Act);
pButton->GetState();
if (pButton->GetCheck())
{
pButton->SetCheck(0);
pButton->SetState(0);
GetDlgItemText(IDC_Crypto_Port_Act,sString);
if (!sString.Compare("Activate"))
{
Executive.Set_Activate(3, Active);
SetDlgItemText(IDC_Crypto_Port_Act,"Deactivate");
}
else
{
Executive.Set_Activate(3,!Active);
SetDlgItemText(IDC_Crypto_Port_Act,"Activate");
}
m_b_Crypto_Port_Act = TRUE;
}
if (m_b_Crypto_Port_Act)
{
Executive.On_Crypto_Apply_Event();
m_b_Crypto_Port_Act = FALSE;
}
if(!Executive.b_Port_Open[3] && ((CButton* )GetDlgItem(IDC_Crypto_Port_Act))->GetCheck() )
{
Executive.OpenPort(3, m_Port_Number);
}
// UpdateData(TRUE);
// UpdateWindow();
}
void C_Control::On_Crypto_Apply_Event()
{
// this function controls the thread starting and stopping.
// the threads are synchronized on a start and a stop event.
// the thread functions that this functions controls are
// those that write data to the ports and to the log files
// if port is currently inactive - start and set timing
if (!b_Port_Status[3])
{
goto startports;
}
else // port already active
{
Activate_Crypto_Port(4, FALSE);
goto startports;
}
startports:
Activate_Crypto_Port(4, TRUE);
Port[3].StartTransmission.SetEvent();
}
bool C_Control::Activate_Crypto_Port(int PortNumber, bool ActiveYN)
{
// this function starts or suspends a port thread depending
// on the state of ActiveYN and opens the log files the first
// time a port is activated
static int Times_Through[4] = {0,0,0,0};
DWORD SuspendCount;
if (ActiveYN) //activate
{
if (Times_Through[PortNumber-1]==0)
{
// Open the log files only the first time a write event happens
// Port[PortNumber-1].OpenLogFiles(FileNames[PortNumber-1]);
Times_Through[PortNumber-1]=1;
}
SuspendCount=PortThread[PortNumber-1]->ResumeThread();
//code based on SuspendCount
}
UINT C_RS_422_Port::Send_Crypto_Key_1()
{
DWORD aword = ::WaitForMultipleObjects(2,EventHandles,FALSE,INFINITE);
//more code
}
There's all the relevant code without going too overboard. Also, the first time SuspendCount is declared in this section, it will be assigned a valid number.