Citation :
 
 
 #include "afx.h"
 void main()
 {
  OVERLAPPED gOverLapped;
  HANDLE hFile;
  DCB MonDCB;
  COMMTIMEOUTS MonCommTimeOuts;
  char inBuffer[20];
  unsigned long nBytesToRead=20;
  unsigned long nBytesRead=0;
  hFile=CreateFile("COM2",GENERIC_WRITE|GENERIC_READ,0,NULL,OPEN_EXISTING,0,NULL);
  if(hFile==INVALID_HANDLE_VALUE)
  {
  	int ErreurCreateFile=GetLastError();
  }
  int Erreur1=GetCommState(hFile,&MonDCB);
  if(Erreur1==0)
  {
  	int ErreurGetCommState=GetLastError();
  }
  MonDCB.BaudRate=CBR_9600;
  MonDCB.Parity=0;
  MonDCB.ByteSize=8;
  MonDCB.StopBits=0;
  int Erreur2=SetCommState(hFile,&MonDCB);
  if(Erreur2==0)
  {
  	int ErreurSetCommState=GetLastError();
  }
  int Erreur3=GetCommTimeouts(hFile,&MonCommTimeOuts);
  if(Erreur3==0)
  {
  	int ErreurGetCommState=GetLastError();
  }
  MonCommTimeOuts.ReadIntervalTimeout=500;
  MonCommTimeOuts.ReadTotalTimeoutMultiplier=1000;
  MonCommTimeOuts.ReadTotalTimeoutConstant=0;
  int Erreur4=SetCommTimeouts(hFile,&MonCommTimeOuts);
  if(Erreur4==0)
  {
  	int ErreurSetCommTimeouts=GetLastError();
  }
 // set up overlapped structure fields   // to simplify this sample, we'll eschew an event handle   gOverLapped.Offset     = 0;   gOverLapped.OffsetHigh = 20;   gOverLapped.hEvent     = NULL;   int i;
 for(i=0;i<=18;i++)
 {
  inBuffer[i]=' ';
 }
 // attempt an asynchronous read operation   DWORD bResult;
 bResult=ReadFile(hFile, &inBuffer, nBytesToRead, &nBytesRead,       &gOverLapped) ;   // if there was a problem, or the async. operation's still pending ...   if (!bResult)   {    DWORD dwError;
     // deal with the error code       switch (dwError = GetLastError())       {           case ERROR_HANDLE_EOF:           {               // we're reached the end of the file               // during the call to ReadFile    
             // code to handle that           }           case ERROR_IO_PENDING:           {               // asynchronous i/o is still in progress                // do something else for a while    //           GoDoSomethingElse() ;                // check on the results of the asynchronous read               bResult = GetOverlappedResult(hFile, &gOverLapped,                   &nBytesRead, FALSE) ;                // if there was a problem ...               if (!bResult)               {                   // deal with the error code                   switch (dwError = GetLastError())                   {                       case ERROR_HANDLE_EOF:                       {                           // we're reached the end of the file                           //during asynchronous operation                       }                        // deal with other error cases                   }               }           } // end case    
         // deal with other error cases       } // end switch   } // end if   CloseHandle(hFile);
 }
 
   |