CreateFile打开串口失败(com10以上)

// get a handle to the port
m_hComm = CreateFile(_T("\\.\COM11"), // communication port string (COMX)
GENERIC_READ | GENERIC_WRITE, // read/write types
0, // comm devices must be opened with exclusive access
NULL, // no security attributes
OPEN_EXISTING, // comm devices must use OPEN_EXISTING
FILE_FLAG_OVERLAPPED, // Async I/O
0); // template must be 0 for comm devices
if (m_hComm == INVALID_HANDLE_VALUE)
{
// port not found
delete [] szPort;
delete [] szBaud;
return FALSE;
}
com10以上,CreateFile的第一个参数要变成\\.\ + COM11
CreateFile打开串口失败(com10以上)_第1张图片

你可能感兴趣的:(C/C++,协议,com组件,mfc)