Here is a snippet of code from one of my C++ programs for opening a com port as a handle.
You have to open it as "\\.\com1" for example. Of course in C++, a backslash in a string has to be doubled to avoid it being treated as an escape sequence (gee, thanks Microsoft, for not using "/" like Unix does!).
char comport_name [64];
sprintf (comport_name, "\\\\.\\COM%d", comport);
HANDLE comhandle = CreateFileA (
comport_name,
GENERIC_READ | GENERIC_WRITE,
0, // no sharing
NULL, // default security attributes
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL
);