void Get_serialport(){
HKEY hKey;
if (::RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Hardware\\DeviceMap\\SerialComm", NULL, KEY_READ, &hKey) == ERROR_SUCCESS){// 打开串口注册表
int i = 0;
char portName[256], commName[256];
DWORD dwLong, dwSize;
while (1)
{
dwLong = dwSize = sizeof(portName);
if (::RegEnumValue(hKey, i, portName, &dwLong, NULL, NULL, (PUCHAR)commName,
&dwSize) == ERROR_NO_MORE_ITEMS) // 枚举串口
break;
PortList.Add(commName); // commName就是串口名字
i++;
}
}
}
VC++获取计算机串口
最新推荐文章于 2024-09-18 11:29:40 发布