In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "C++ how to get system activities, available serial ports and names". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next, let the editor take you to learn how C++ can get system activities, available serial ports and names.
CreateFile method:
Void GetComList_256 (CComboBox * CCombox) / / get the available com ports to support up to 256
{
CString strCom,strComOpen
Int nCom = 0
Int count = 0
HANDLE hCom
CCombox- > ResetContent ()
Do
{
NCom++
StrCom.Format ("COM%d", nCom)
StrComOpen.Format ("\\.\\ COM%d", nCom)
HCom = CreateFile (strComOpen, GENERIC_READ | GENERIC_WRITE, 0, NULL
OPEN_EXISTING, FILE_FLAG_OVERLAPPED, 0)
If (INVALID_HANDLE_VALUE = = hCom)
{
DWORD error=::GetLastError (); / / get the error message
}
Else
{
CCombox- > AddString (strCom)
Count++
}
CloseHandle (hCom)
} while (nComSetCurSel (0)
}
*
How to read the registry:
Int GetComList_Reg (CComboBox * CCombox)
{
HKEY hkey
Int result
Int I = 0
CString strComName;// serial port name
Detailed name of CString strDrName;// serial port
Result = RegOpenKeyEx (HKEY_LOCAL_MACHINE
_ T ("Hardware\\ DeviceMap\\ SerialComm")
NULL
KEY_READ
& hkey)
If (ERROR_SUCCESS = = result) / / Open the serial port registry
{
TCHAR portName [0x100], commName [0x100]
DWORD dwLong, dwSize
CCombox- > ResetContent ()
Do
{
DwSize = sizeof (portName) / sizeof (TCHAR)
DwLong = dwSize
Result = RegEnumValue (hkey, I, portName, & dwLong, NULL, NULL, (LPBYTE) commName, & dwSize)
If (ERROR_NO_MORE_ITEMS = = result)
{
/ / enumerate serial ports
Break; / / commName is the serial port name "COM2"
}
StrComName=commName
StrDrName = portName
/ / find the first'\ 'from right to left and get the length of the string on the left
Int len = strDrName.ReverseFind ('\')
/ / get the string to the left of'\'
CString strFilePath = strDrName.Left (len+1)
/ / get the string to the right of'\'
CString fileName = strDrName.Right (strDrName.GetLength ()-len-1)
FileName = strComName + _ T (":") + fileName
CCombox- > AddString (fileName)
ITunes +
} while (1)
RegCloseKey (hkey)
}
CCombox- > SetCurSel (0)
Return i
}
After reading, it can also be added to the combo box, and can be added to the data as needed.
At this point, I believe that "C++ system activities, available serial ports and names of the method" have a deeper understanding, you might as well to the actual operation of it! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.