int CUtil::GetSystemPorts(CString *pNameList, CString *pPortList)
{
CRegKey RegKey;
int nCount = 0;
if(RegKey.Open(HKEY_LOCAL_MACHINE, "Hardware\\DeviceMap\\SerialComm") == ERROR_SUCCESS)
{
while(true)
{
char ValueName[_MAX_PATH];
unsigned char ValueData[_MAX_PATH];
DWORD nValueSize = _MAX_PATH;
DWORD nDataSize = _MAX_PATH;
DWORD nType;
if(::RegEnumValue(HKEY(RegKey), nCount, ValueName, &nValueSize, NULL, &nType, ValueData, &nDataSize) == ERROR_NO_MORE_ITEMS)
{
break;
}
if(pNameList)
pNameList[nCount] = ValueName;
if(pPortList)
pPortList[nCount] = ValueData;
nCount++;
}
}
return nCount;
}
转载于:https://www.cnblogs.com/guangxin/archive/2012/03/18/2405238.html