| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- #include "../pch/pch.h"
- #include "CComHelper.h"
- CComHelper::CComHelper()
- {
- }
- CComHelper::~CComHelper()
- {
- }
- std::vector<std::wstring> CComHelper::getComPort()
- {
- std::vector<std::wstring> comVector;
- HKEY hKey;
- TCHAR portName[256], commName[256];
- // 打开串口注册表对应的键值
- if (ERROR_SUCCESS == ::RegOpenKeyEx(HKEY_LOCAL_MACHINE, L"Hardware\\DeviceMap\\SerialComm", NULL, KEY_READ, &hKey))
- {
- int i = 0;
- int mm = 0;
- DWORD dwLong, dwSize;
- while (TRUE)
- {
- dwLong = dwSize = sizeof(portName);
- // 枚举串口
- if (ERROR_NO_MORE_ITEMS == ::RegEnumValue(hKey, i, portName, &dwLong, NULL, NULL, (PUCHAR)commName, &dwSize))
- {
- break;
- }
- comVector.push_back(commName);
- i++;
- }
- // 关闭注册表
- RegCloseKey(hKey);
- }
- else
- {
- MessageBox(NULL, L"您的计算机的注册表上没有HKEY_LOCAL_MACHINE:Hardware\\DeviceMap\\SerialComm项", L"警告", MB_OK);
- }
- // 返回串口号
- return comVector;
- }
|