Visual C++通信编程实例
源代码在线查看: d254.bmp.txt
if (m_nSendOut != m_nSendln)
{
memcpy(pparam, &m_SmSend[m_nSendOut], sizeof(SM_PARAM》;
m_nSendOut++;
if (m_nSendOut >= MAX_SM_SEND)
m_nSendOut = 0;
fSuccess = TRUE;
}
LeaveCriticalSection(&m_c sS end);
return fSuccess;
void CSmsTraffic::PutRecvMessage(SM_PARAM* pparam,int nCount)
{
EnterCritic alSection(&m_csRecv);
for (int i = 0; i < nCount; i++)
{
memcpy(&m_SmRecv [m_nRecvln], pparam, sizeof(SM_PARAM》;
m_nRecvln++;
, if (m_nRecvln >= MAX_SM_RECV)
m_nRecvln = 0;
pparam++,
}
LeaveCriticalSection(&m_csRecv) ;
}
//从接收队列中取一条短消息
BOOL CSmsTraffic::GetRecvMessage(SM_PARAM* pparam)
{
BOOL fSuccess= FALSE;
EnterCriticalSection(&m_csRecv);
if (m_nRecvOut!=m_nRecvln)
{
memcpy(pparam, &m_SmRecv[m_nRecvOut], sizeof(SM_PARAM》;
m_nRecvOut++;
if (m_nRecvOut>=MAX_SM_RECV)
m_nRecvOut=0;
f'Success= TRUE;
)
LeaveCriticalSection(&m_csRecv);
return fSuccess;
}
最后,编辑短消息进程函数,由于该函数内容较长,就不在这里具体陈述函数体内容,
读者可以参看随书光盘相应程序中的函数UINT CSmsTraffic::SmsThread(LPVOID IParam)。
254