MFC scan COM port Program

Source: Internet
Author: User

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

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.