FindCommPort()
{
HKEY hKey;
int rtn;
//m_ctrlComboComPort为对话框中的combobox框
m_ctrlComboComPort.ResetContent();
rtn = RegOpenKeyEx( HKEY_LOCAL_MACHINE, "Hardware\\DeviceMap\\SerialComm",
NULL, KEY_READ, &hKey); // 打开串口注册表
if( rtn == ERROR_SUCCESS)
{
int i=0;
char portName[256],commName[256];
DWORD dwLong,dwSize;
while(1)
{
dwSize = sizeof(portName);
dwLong = dwSize;
// If no more items to enumerate, the Rk.EnumValue returns FALSE
rtn = RegEnumValue( hKey, i, portName, &dwLong,
NULL, NULL, (PUCHAR)commName, &dwSize );
if( rtn == ERROR_NO_MORE_ITEMS ) // 枚举串口
break;
m_ctrlComboComPort.AddString(commName);
i++;
}
RegCloseKey(hKey);
}
}
此段代码来自http://blog.csdn.net/fuyangchang/article/details/2685746
http://topic.csdn.net/u/20090220/09/cabbac21-3ff5-4590-80e6-f989ef006576.html