if(::RegOpenKeyEx( HKEY_LOCAL_MACHINE, _T("Hardware//DeviceMap//SerialComm"), NULL, KEY_READ, &hKey ) == ERROR_SUCCESS ) //打开串口注册表对应的键值 {int i=0;TCHAR 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(_T("在HKEY_LOCAL_MACHINE:Hardware//DeviceMap//SerialComm里找不到串口!!!")); } RegCloseKey(hKey); }
转载自:/blog/u/2956/archives//279.html