Serial communication under Windows9x / WindowsNT in Borlan C++ Builder 5
I had wrote an application in C++ Builder 5, that opens COM port :
HANDLE hCOM;
OVELRAPPED ovRead;
OVELRAPPED ovWrite;
HANDLE ComOVRSendEvents[] = { hComExitEvent, hCloseSender, ovWrite.hEvent };
1)create COM descriptor
hCOM=CreateFile("COM1",
GENERIC_READ|GENERIC_WRITE, /* access rigths */
0, /* sharing - no sharing. Object cannot be accessed till file is closed */
(LPSECURITY_ATTRIBUTES)NULL, /* security attributes */
OPEN_EXISTING, /* creation mode ... open only if file exists */
FILE_FLAG_OVERLAPPED , /* FILE_FLAG_NO_BUFFERING ??*/
NULL /* template file handle. NULL for CreateFile*/
);
--> Ok hComm != INVALID_HANDLE_VALUE;
2) create overlapped structure for async. communication
memset( &ovRead, NULL, sizeof(ovRead) );
// create events that signals the end of data reception
ovRead.hEvent = CreateEvent((LPSECURITY_ATTRIBUTES)NULL,FALSE,FALSE,NULL );
memset( &ovWrite, NULL, sizeof(ovWrite) );
// create events that signals the end of data trensmission
ovWrite.hEvent = CreateEvent((LPSECURITY_ATTRIBUTES)NULL,FALSE,FALSE,NULL );
--> Ok. events created.
3) try to send some data in a cycle (the code is runnig ito separated thread)
if (WriteFile(hCOM, &bData, sizeof(bData), &dwBytes, ovWrite))
continue; // if write successfull finished
if(GetLastError()!=ERROR_IO_PENDING )
continue; // an error. not handled
switch( WaitForMultipleObjects(3, ComOVRSendEvents, FALSE, 1000) ){
case WAIT_OBJECT_0+0: // the application exits
case WAIT_OBJECT_0+1: // the sender is restarted by monitor due to time out
if(!GetOverlappedResult(hCOM,&ovWrite,&bytesWrote,false)){
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
NULL,GetLastError(),MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR) &lpMsgBuf,0,NULL);
// Display the string.
MessageBox( NULL,(char*) lpMsgBuf, "cOMM_KERNEL.:.ThKill: GetLastError",
MB_OK|MB_ICONINFORMATION );
// Free the buffer.
LocalFree( lpMsgBuf );
}
return (-1);
case WAIT_OBJECT_0+2: // ovr opperation finished
// Ok
break;
}
-->> Well, each time under windows Me I have following message "Overlapped I/O event is not in a signaled state". This means, that every time the sender is restarted by sender monitor. The switch statement ends at case WAIT_OBJECT_0+1.
I have no ideia what is wrong? Cause under Win2k and WinXp it works with no errors.
Thank you.

