线程函数传递参数传不进去。
DWORD WINAPI CCom::readProc(LPVOID lpparam)
{
CCom* com=(CCom*)lpparam;
DWORD readCount=0;
DWORD readedlen=0;
int i=0;
while(com->_isreceiving==true)
{
readCount=1;
readedlen=0;
i=0;
while(readCount>0)
{
ReadFile(com->_hComDev,com->readbuff+readedlen,1024-readedlen,&readCount,&(com->_overlapped));
if(i>10) break;
i++;
Sleep(20);
}
if(readedlen>0)
{
if(com->_onReceiveData!=NULL)
{
com->_onReceiveData(com->readbuff,readedlen);
}
}
}
return 0;
}
void CCom::startReceiveData()
{
DWORD threadid;
_isreceiving=true;
_com=this;
HANDLE hthread=CreateThread(NULL,0,readProc,(LPVOID)_com,NULL,&threadid);
//这儿传进去的_com好像是错的。 _isreceiving 是未初始化的。
//HANDLE hthread=CreateThread(NULL,0,readProc,(LPVOID)NULL,NULL,&threadid);
}