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 ;
sprintf (comport_name, "\\\\.\\COM%d", comport);
HANDLE comhandle = CreateFileA (
GENERIC_READ | GENERIC_WRITE,
0, // no sharing
NULL, // default security attributes