I’m trying to communicate with a virtual serial port using MinGW on a Windows 7 x64 machine. According to the Device Manager my device is available at COM27. I have this code:
#include <windows.h>
#include <stdio.h>
int main()
{
HANDLE hComm;
const WCHAR FileFullPath[] = {L"COM1"} ;
hComm = CreateFile( (LPCTSTR)FileFullPath,
GENERIC_READ | GENERIC_WRITE,
0,
0,
OPEN_EXISTING,
FILE_FLAG_OVERLAPPED,
0);
if (hComm == INVALID_HANDLE_VALUE) {
printf("Invalid value: %d\r\n", GetLastError());
}
}
Which gives me a ERROR_FILE_NOT_FOUND (error code 2). Output:
Invalid value: 2
If I change the port name to COM1 (another port that I have), fails to create the file with error 1450, or ERROR_NO_SYSTEM_RESOURCES.
What am I doing wrong? I accept alternatives to MinGW, it’s not mandatory.
The COM port name should be
\\.\COM1(\\\\.\\COM1after escaping the backslashes), notCOM1.