2,640
社区成员
发帖
与我相关
我的任务
分享
void ProcessSndBuffer(BYTE *buffer, DWORD size, int comIndex)
{
try
{
OVERLAPPED m_osWrite;
memset(&m_osWrite, 0, sizeof(m_osWrite));
m_osWrite.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
COMSTAT ComStat;
DWORD dwErrorFlags, dwBytesWritten, dwRes;
BOOL bWriteStat;
ClearCommError(hComArray[comIndex], &dwErrorFlags, &ComStat);
bWriteStat = WriteFile(hComArray[comIndex], buffer, size, &dwBytesWritten, &m_osWrite);
if(!bWriteStat)
{
DWORD dwLastError = GetLastError();
if(GetLastError() == ERROR_IO_PENDING)
{
dwRes = WaitForSingleObject(m_osWrite.hEvent, 1000);
if (dwRes == WAIT_OBJECT_0)
{
while(!GetOverlappedResult(hComArray[comIndex], &m_osWrite, &dwBytesWritten, TRUE))
{
DWORD dwError = GetLastError();
if (dwError == ERROR_IO_INCOMPLETE)
continue;
}
}
}
}
CloseHandle(m_osWrite.hEvent);
}
catch (...)
{
}
}
void ProcessSndBuffer(BYTE *buffer, DWORD size, int comIndex)
{
try
{
OVERLAPPED m_osWrite;
#if 1
m_osWrite.hEvent = 0;
m_osWrite.Internal = 0;
m_osWrite.InternalHigh = 0;
m_osWrite.Offset = 0;
m_osWrite.OffsetHigh = 0;
#endif
COMSTAT ComStat;
DWORD dwErrorFlags, dwBytesWritten, dwRes;
BOOL bWriteStat;
//memset(&m_osWrite, 0, sizeof(m_osWrite));
m_osWrite.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
ClearCommError(hComArray[comIndex], &dwErrorFlags, &ComStat);
bWriteStat = WriteFile(hComArray[comIndex], buffer, size, &dwBytesWritten, &m_osWrite);
if(!bWriteStat)
{
DWORD dwLastError = GetLastError();
if(GetLastError() == ERROR_IO_PENDING)
{
dwRes = WaitForSingleObject(m_osWrite.hEvent, 1000);
if (dwRes == WAIT_OBJECT_0)
{
while(!GetOverlappedResult(hComArray[comIndex], &m_osWrite, &dwBytesWritten, TRUE))
{
DWORD dwError = GetLastError();
if (dwError == ERROR_IO_INCOMPLETE)
continue;
}
}
}
}
CloseHandle(m_osWrite.hEvent);
}
catch (...)
{
}
}
不用memset,俺纯粹一个一个成员赋0,效果应该和memset一样了吧?
然后。。。就悲剧了!还是这个错误。。。