参考一下 EnumDisplaySettings 函数的帮助,你就理解怎么做啦 在 2K、XP 下,设备名是以 \\.\ 开头的 lpszDeviceName Pointer to a null-terminated string that specifies the display device whose graphics mode the function will obtain information about. This parameter can be NULL. A NULL value specifies the current display device on the computer that the calling thread is running on. If lpszDeviceName is not NULL, the string must be of the form \\.\DisplayX, where X can have the values 1, 2, or 3. COM10 或者以上即是 \\.\COM10----------------------------------- 现在混水园了!
在 2K、XP 下,设备名是以 \\.\ 开头的
lpszDeviceName
Pointer to a null-terminated string that specifies the display device whose graphics mode the function will obtain information about.
This parameter can be NULL. A NULL value specifies the current display device on the computer that the calling thread is running on. If lpszDeviceName is not NULL, the string must be of the form \\.\DisplayX, where X can have the values 1, 2, or 3. COM10 或者以上即是 \\.\COM10-----------------------------------
现在混水园了!
{
char portName[MAX_PATH];
// 在 C/C++ 字符串中,\\ 才代表 字符 \
wsprintf(portName, "\\\\.\\COM%d", comID + 1); // comID = 0~31
comHandle = CreateFile(portName, // Name
GENERIC_READ | GENERIC_WRITE, // Access mode
0, // Share mode
NULL, // Security attributes
OPEN_EXISTING, // How to create
FILE_ATTRIBUTE_NORMAL | // File attributes
FILE_FLAG_OVERLAPPED,
NULL // Template
);
if (comHandle == INVALID_HANDLE_VALUE)
comLastError = GetLastError();
else
comLastError = NO_ERROR;
return comLastError;
} // ComWin32::Open()