I'm trying to write a program that listens on the COM port. I have a remote control and an IR that connects to the COM port.
I wonder if it's possible to use CreateFile() and ReadFile() for this.

My current code are below but it does'nt present any information to screen (as it should).
It seems that ReadFile() does'nt get any data. Perhaps it has to be done at a lower level?

Code:
int main(void)
{
	HANDLE hcom;
	DCB dcb;
	LPDWORD nBytesRead = NULL; 
	OVERLAPPED OverLapped;
	//DWORD dwEvtMask=0;
	
	char inBuffer[128] = {0};
	const char *pcComPort = "COM4";

	
	// Create a handle to COM port
	hcom = CreateFile(pcComPort,		// Using pcComPort
		GENERIC_READ,	
		0,								// Opened with exclusive access
		NULL,							// No security options
		OPEN_EXISTING,					// Must use OPEN_EXISTING with COM ports
		FILE_FLAG_OVERLAPPED,			// Overlapped I/O
		NULL);							// Must be NULL with COM ports

	if (hcom == INVALID_HANDLE_VALUE) {
		GetError();
		return 0;
	}

	// ----------START CONFIGURATION----------
	if (!GetCommState(hcom, &dcb)) {
		GetError();
		return 0;
	}
	
	// Fill in DCB structure.
	dcb.BaudRate = CBR_9600;
	dcb.ByteSize = 8;
	dcb.Parity = NOPARITY;
	dcb.StopBits = ONESTOPBIT;

	// Update configuration.
	if (!SetCommState(hcom, &dcb)) {
		GetError();
		return 0;
	}
	// ----------END CONFIGURATION----------

	while (1) {
		/*
		SetCommMask(hcom, EV_RXCHAR);
		WaitCommEvent(hcom, &dwEvtMask, &OverLapped);
		*/
		ReadFile(hcom, inBuffer, sizeof(inBuffer), nBytesRead, &OverLapped);
		
		if (nBytesRead)
			printf("%d, %s", *nBytesRead, inBuffer);
		_sleep(5);
	}
	
	CloseHandle(hcom);
	return 0;
}