I am trying to communicate with a virtual serial port using MinGW on a Windows 7 x64 computer. 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 ERROR_FILE_NOT_FOUND( error code 2 ). Output:
Invalid value: 2
If I changed the port name to COM1(another port that I have), it was not possible to create a file with error 1450 or ERROR_NO_SYSTEM_RESOURCES.
What am I doing wrong? I accept MinGW alternatives, this is not necessary.
source
share