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