MFC scan COM port Program
MFC scan COM port program source code
Features:
The core function is scan. Not only can the actual port of COM such as Bluetooth and printer be scanned, but also the port of com from the virtual machine.
Not only the name can be displayed, but also the specific parameters of the manufacturer
/* <Br/> func name: Scan <br/> Description: scan and display the COM port information <br/> This is the main function of the app. it detect your port, as well as the virtual port. <br/> */</P> <p> hresult csmartscanerdlg: scan (void) <br/>{</P> <p> hdevinfo; <br/> sp_devinfo_data deviceinfodata; <br/> dword I; </P> <p> // create a hdevinfo with all present devices. <br/> hdevinfo = setupdigetclassdevs (L Pguid) & guid_devclass_ports, <br/> 0, // enumerator <br/> 0, <br/> digcf_present ); </P> <p> If (hdevinfo = invalid_handle_value) <br/>{< br/> // insert error handling here. <br/> return 1; <br/>}</P> <p> // Enumerate through all devices in set. </P> <p> deviceinfodata. cbsize = sizeof (sp_devinfo_data); <br/> for (I = 0; setupdienumdeviceinfo (hdevinfo, I, <br/> & deviceinfodata); I ++) <br/>{< br/> DWORD datat; <br/> lptst R buffer = NULL; <br/> DWORD buffersize = 0; </P> <p> // <br/> // call function with null to begin, <br/> // then use the returned buffer size <br/> // to alloc the buffer. keep calling until <br/> // success or an unknown failure. <br/> // <br/> while (! Setupdigetdeviceregistryproperty (<br/> hdevinfo, <br/> & deviceinfodata, <br/> spdrp_friendlyname, <br/> & datat, <br/> (pbyte) buffer, <br/> buffersize, <br/> & buffersize) <br/>{< br/> If (getlasterror () ==< br/> error_insufficient_buffer) <br/> {<br/> // change the buffer size. <br/> If (buffer) localfree (buffer); <br/> buffer = (lptstr) localalloc (lptr, buffersize ); <br/>}< br/> else <br/> {<br/> // insert error Handling here. <br/> break; <br/>}</P> <p> // printf ("Result: [% s]/n ", buffer); </P> <p>/** <br/> disp is MFC Edit Control cstring variable. <br/> here, I just use it to display the scan results. <br/> the buffer just contains the result. <br/> and if you want to get other information, just change <br/> spdrp_friendlyname (please look up in msdn) <br/> */<br/> Disp. append (buffer); <br/> Disp. append (_ T ("/R/N" ); <Br/> conedit. setwindowtextw (Disp. getstring (); </P> <p >}</P> <p> setupdidestroydeviceinfolist (hdevinfo); </P> <p> If (! Wcscmp (Disp. getstring (), _ T ("/R/N") {<br/> MessageBox (_ T ("no device find "), _ T ("prompt"); <br/>}</P> <p> return s_ OK; <br/>}
MFC scan COM port program source code