how to create teechart in a subthread in mfc
Posted: Mon Apr 27, 2015 8:42 am
I want to use teechart to draw powersprectrum in my application which is based on MFC. In my subthread,it occurs the error "access violation at address in module 'TeeChart5.ocx'",i don't know how to solve this problem.Anyone can tell me how to solve this problem,please. My code as follow:
Code: Select all
UINT CEEG_ONLINEDlg::CalculateThread(LPVOID pParam)
{
CEEG_ONLINEDlg *p_Calculate = (CEEG_ONLINEDlg*)pParam; //p_Calculate可以调用类中的成员函数;
while (TRUE)
{
//float bFil[] = { 0.7403, 0.0005, -3.6991, -0.001, 7.3955, -0, -7.3955, 0.001, 3.6991, -0.0005, -0.7403 };//IIR,10or,Fs=100,bp(0.5,3,48,50)
//float aFil[] = { 1, 0.1211, -4.3896, -0.4116, 7.7502, 0.5284, -6.8754, -0.3033, 3.0632, 0.0656, -0.5481 };
if (bThreadControl)
{
memcpy(p_Calculate->pCalculateBuffer, m_pBuffer, sizeof(short) * nChannelNum * NPT_PER_READ); //将采集到的数据复制到计算线程的临时存储区;
p_Calculate->Calculate();
//::SendMessage(AfxGetApp()->m_pMainWnd->m_hWnd, WM_MYMESSAGE, 0, 0);
CSeries series1 = ((CSeries)(p_Calculate->m_MyChart).Series(0));
series1.Clear();
for (int i = 0; i != p_Calculate->len; ++i)
{
series1.AddXY(i * p_Calculate->pwScale, p_Calculate->ampR[1][i], NULL, RGB(255, 0, 0));
}
SetEvent(g_hEventForCollect);
}
else
{
break;
}
}
return 0;
}