Windows Enumeration serial port

Source: Internet
Author: User

1. Enumeration Key values

Hkey_local_machine\hardware\devicemap\serialcomm

2. SetupAPI mode

1 intENUMPORTSWDM ()2 {3     intI, dwdetdatasize;4TCHAR fname[ the], locinfo[ the];5 Hdevinfo Hdevinfo;6sp_device_interface_detail_data*Pdetdata;7 Sp_device_interface_data Ifcdata;8 Sp_devinfo_data Devdata;9 Ten     Static ConstGUID ___guid_class_comport =  One{0x86e0d1e0l,0x8089,0x11d0, {0x9c,0xE4,0x08,0x00,0x3e,0x30,0x1F,0x73 } }; A     /*static const GUID ___guid_class_comport = - {0xad498944, 0x762f, 0x11d0, {0x8d, 0xCB, 0x00, 0xC0, 0x4f, 0xC3, 0x35, 0x8c}};*/ -  the  -Hdevinfo = Setupdigetclassdevs (&___guid_class_comport, NULL, NULL, Digcf_present |digcf_deviceinterface); -     if(Hdevinfo = =Invalid_handle_value) -     { +         return-1; -     } +  ADwdetdatasize =sizeof(Sp_device_interface_detail_data) + the; atPdetdata = (sp_device_interface_detail_data*)calloc(1, dwdetdatasize); -     if( !pdetdata) -     { - setupdidestroydeviceinfolist (hdevinfo); -         return-1; -     } in  -Ifcdata.cbsize =sizeof(sp_device_interface_data); toPdetdata->cbsize =sizeof(sp_device_interface_detail_data); +  -      for(i =0; Setupdienumdeviceinterfaces (Hdevinfo, NULL, &___guid_class_comport, I, &ifcdata); i + + ) the     { *memset (&devdata,0,sizeof(Sp_devinfo_data)); $Devdata.cbsize =sizeof(sp_devinfo_data);Panax Notoginseng  -         if( ! Setupdigetdeviceinterfacedetail (Hdevinfo, &ifcdata, Pdetdata, Dwdetdatasize, NULL, &devdata)) the         { +              Break; A         } the  +MessageBox (NULL, Pdetdata->devicepath, TEXT ("PATH"), MB_OK); -         if(Setupdigetdeviceregistryproperty (Hdevinfo, &devdata, Spdrp_friendlyname, NULL, (pbyte) fname,sizeof(fname), NULL)) $         { $MessageBox (NULL, fname, TEXT ("NAME"), MB_OK); -         } -  the         if(Setupdigetdeviceregistryproperty (Hdevinfo, &devdata, Spdrp_location_information, NULL, (PBYTE) Locinfo,sizeof(Locinfo), NULL)) -         {Wuyi             if(Strcmpn (Locinfo, TEXT ("USB"),3) ==0 ) the             { -MessageBox (NULL, TEXT ("USB"), TEXT ("TYPE"), MB_OK); Wu             } -         } About     } $  -      Free(pdetdata); - setupdidestroydeviceinfolist (hdevinfo); -     return 0; A}

Windows Enumeration serial port

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.