Warning: That file was not part of the compilation database. It may have many parsing errors.

1/****************************************************************************
2**
3** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4** Contact: http://www.qt-project.org/legal
5**
6** This file is part of the tools applications of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and Digia. For licensing terms and
14** conditions see http://qt.digia.com/licensing. For further information
15** use the contact form at http://qt.digia.com/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 2.1 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 2.1 requirements
23** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24**
25** In addition, as a special exception, Digia gives you certain additional
26** rights. These rights are described in the Digia Qt LGPL Exception
27** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28**
29** GNU General Public License Usage
30** Alternatively, this file may be used under the terms of the GNU
31** General Public License version 3.0 as published by the Free Software
32** Foundation and appearing in the file LICENSE.GPL included in the
33** packaging of this file. Please review the following information to
34** ensure the GNU General Public License version 3.0 requirements will be
35** met: http://www.gnu.org/copyleft/gpl.html.
36**
37**
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#include "serenum.h"
43#include <QByteArray>
44#include <QString>
45#include <QDebug>
46#include <windows.h>
47#include <windef.h>
48#include <setupapi.h>
49#include <devguid.h>
50#include <winreg.h>
51#include <shlwapi.h>
52
53//{4d36e978-e325-11ce-bfc1-08002be10318}
54//DEFINE_GUID(GUID_DEVCLASS_PORTS, 0x4D36E978, 0xE325, 0x11CE, 0xBF, 0xC1, 0x08, 0x00, 0x2B, 0xE1, 0x03, 0x18 );
55
56QList<SerialPortId> enumerateSerialPorts(int)
57{
58 DWORD index=0;
59 SP_DEVINFO_DATA info;
60 GUID guid = GUID_DEVCLASS_PORTS;
61 HDEVINFO infoset = SetupDiGetClassDevs(&guid, 0, 0, DIGCF_PRESENT);
62 QString valueName(16384, 0);
63 QList<SerialPortId> list;
64
65 for (index=0;;index++) {
66 ZeroMemory(&info, sizeof(SP_DEVINFO_DATA));
67 info.cbSize = sizeof(SP_DEVINFO_DATA);
68 if (!SetupDiEnumDeviceInfo(infoset, index, &info))
69 break;
70 QString friendlyName;
71 QString portName;
72 DWORD size=0;
73 SetupDiGetDeviceRegistryProperty(infoset, &info, SPDRP_FRIENDLYNAME, 0, 0, 0, &size);
74 QByteArray ba(size, 0);
75 if(SetupDiGetDeviceRegistryProperty(infoset, &info, SPDRP_FRIENDLYNAME, 0, (BYTE*)(ba.data()), size, 0)) {
76 friendlyName = QString((const QChar*)(ba.constData()), ba.size() / 2 - 1);
77 }
78 HKEY key = SetupDiOpenDevRegKey(infoset, &info, DICS_FLAG_GLOBAL, 0, DIREG_DEV, KEY_READ);
79 if(key != INVALID_HANDLE_VALUE) {
80 //RegGetValue not supported on XP, SHRegGetValue not supported by mingw, so use the old method of enumerating all the values
81 for (DWORD dwi=0;;dwi++) {
82 DWORD vsize = valueName.size();
83 if (ERROR_SUCCESS == RegEnumValue(key, dwi, (WCHAR*)(valueName.data()), &vsize, 0, 0, 0, &size)) {
84 if (valueName.startsWith("PortName")) {
85 QByteArray ba(size, 0);
86 vsize = valueName.size();
87 if(ERROR_SUCCESS == RegEnumValue(key, dwi, (WCHAR*)(valueName.data()), &vsize, 0, 0, (BYTE*)(ba.data()), &size)) {
88 portName = QString((const QChar*)(ba.constData()), ba.size() / 2 - 1);
89 }
90 }
91 } else {
92 break;
93 }
94 }
95 RegCloseKey(key);
96 }
97 SerialPortId id;
98 id.portName = portName;
99 id.friendlyName = friendlyName;
100 list.append(id);
101 }
102 SetupDiDestroyDeviceInfoList(infoset);
103 return list;
104}
105
106

Warning: That file was not part of the compilation database. It may have many parsing errors.