VC++獲取計算機串列埠
阿新 • • 發佈:2019-02-06
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++;
}
}
}