Serial programming-Enumerate through the serial port, get the PC all serial port name, traverse registry key, RegEnumValue usage

Source: Internet
Author: User

On the internet to find a few examples of traversing the serial port, either the code is not complete, or there is a bug, such as reading the serial number is more than 10.
After my finishing, now share the final code, VS2008 under the compilation.

This method is also useful for traversing Windows power-on startup items with just a few modifications.

void Cenumportdlg::enumport (void) {HKEY HKEY; LPCTSTR lpsubkey= "hardware\\devicemap\\serialcomm\\"; if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, Lpsubkey, 0, key_read, &hkey)! = ERROR_SUCCESS) {   return;} #define Name_len -Char Szvaluename[name_len]; BYTE Szportname[name_len]; LONG status; DWORD dwindex = 0; DWORD dwsizevaluename=100; DWORD dwsizeofportname=100; DWORD Type; Dwsizevaluename = Name_len; Dwsizeofportname = Name_len; do {   status = RegEnumValue (HKey, dwindex++, szValueName, &dwsizevaluename, NULL, &type, Szportname,    &dwsizeofportname);   if (status = = ERROR_SUCCESS))   {    m_lstport.addstring ((char *) szportname);      }   Every read once dwsizevaluename and Dwsizeofportname will be modified   //attention must be reset, or there will be a very strange error, I tried because there is no reset, there is no read COM more than 10 of the serial port   Dwsizevaluename = Name_len;   

  

Transferred from: http://www.gzzsc.net

Serial Programming-enumerate through the serial port, get all the serial port name of PC, traverse registry key, RegEnumValue usage

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.