从注册表获取所有的串口[Windows]

http://blog.csdn.net/loongee/article/details/4038339

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);  
    }



你可能感兴趣的:(串口)