Communication with COM1 or COM2

I'm looking for creating a real-to-time communication via a serial port
such as COM1 or COM2.
In fact, I have used the createfile, the readfile and writefile function
but i'm sure i don't give the rights definition for them. I Would like to
use the same port to send and to receive data.

Thank you for helping me