I have written my own component for serial communications using the CreateFile function fom the MS Windows SDK.
Below is the open COM port code
// Open COM Port
bool __fastcall COMThread::OpenCOMPort(COMData *ComPort)
{
//Open the COM port
//Set End_Of_Data_Event Character
cEndOfDataEventChar = ComPort->cEndOfDataEventChar;
//Set Hide Control Character
bHideControlCharacters = cComPortData.bHideControlCharacters;
//Set Translate Control Character
bTranslateControlCharacters = cComPortData.bTranslateControlCharacters;
//If this is not a valid file handle
if((hCommDevice = CreateFile(ComPort->COMPortName.c_str(),
GENERIC_READ | GENERIC_WRITE,
0,
NULL,
OPEN_EXISTING,
FILE_FLAG_OVERLAPPED,
NULL)) == INVALID_HANDLE_VALUE) {
//Report the error and return
dwLastError = GetLastError();
return false;
}
else {
//Setup the event handler for the component
if(!SetCommCommunications(ComPort)) {
return false;
}
else {
return true;
}
}
}
COMData is a Structure containing info about the COM port as below:
typedef struct COMDATA {
bool bCTS;
bool bDSR;
bool bHideControlCharacters;
bool bTranslateControlCharacters;
bool bXOnXOff;
char cEndOfDataEventChar;
DWORD dwBaudRate;
DWORD dwDataBits;
DWORD dwParity;
DWORD dwStopBits;
String COMPortName;
} COMData;
I had a lot of help from Timothy S. Monk's book "Windows Programmer's Guide to Serial Communications" SAMS Publishing, 1992 but the time spent working on it was worth it.
Hope this starting point helps.