这个函数是读注册表的
void FindCommPort(CComboBox *pComboBox ) { HKEY hKey; #ifdef _DEBUG ASSERT( pComboBox != NULL ); pComboBox->AssertValid(); #endif 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; pComboBox->AddString( commName ); // commName就是串口名字 i++; } if( pComboBox->GetCount() == 0 ) { ::AfxMessageBox("在HKEY_LOCAL_MACHINE:Hardware\\DeviceMap\\SerialComm里找不到串口!!!"); } RegCloseKey(hKey); } }