WinStd
Additional templates and function helpers for Microsoft Windows using Standard C++ classes
SetupAPI.h
1/*
2 SPDX-License-Identifier: MIT
3 Copyright © 1991-2022 Amebis
4 Copyright © 2016 GÉANT
5*/
6
7#pragma once
8
9#include "Common.h"
10#include <SetupAPI.h>
11
12namespace winstd
13{
19
23 class setup_device_info_list : public handle<HDEVINFO, INVALID_HANDLE_VALUE>
24 {
25 WINSTD_HANDLE_IMPL(setup_device_info_list, INVALID_HANDLE_VALUE)
26
27 public:
34 {
35 if (m_h != invalid)
37 }
38
48 __declspec(deprecated("Use SetupDiCreateDeviceInfoList"))
49 bool create(
50 _In_opt_ const GUID * ClassGuid,
51 _In_opt_ HWND hwndParent) noexcept
52 {
53 handle_type h = SetupDiCreateDeviceInfoList(ClassGuid, hwndParent);
54 if (h != invalid) {
55 attach(h);
56 return true;
57 }
58 else
59 return false;
60 }
61
71 __declspec(deprecated("Use SetupDiGetClassDevsEx"))
72 bool create(
73 _In_opt_ const GUID * ClassGuid,
74 _In_opt_ PCTSTR Enumerator,
75 _In_opt_ HWND hwndParent,
76 _In_ DWORD Flags,
77 _In_opt_ HDEVINFO DeviceInfoSet,
78 _In_opt_ PCTSTR MachineName,
79 _Reserved_ PVOID Reserved) noexcept
80 {
81 handle_type h = SetupDiGetClassDevsEx(ClassGuid, Enumerator, hwndParent, Flags, DeviceInfoSet, MachineName, Reserved);
82 if (h != invalid) {
83 attach(h);
84 return true;
85 }
86 else
87 return false;
88 }
89
90 protected:
96 void free_internal() noexcept override
97 {
98 SetupDiDestroyDeviceInfoList(m_h);
99 }
100 };
101
106 {
109
110 public:
117 _In_ HDEVINFO DeviceInfoSet,
118 _Inout_opt_ PSP_DEVINFO_DATA DeviceInfoData,
119 _In_ DWORD DriverType) noexcept :
120 m_DeviceInfoSet (DeviceInfoSet),
121 m_DeviceInfoData(DeviceInfoData),
122 m_DriverType (DriverType)
123 {
124 m_result = SetupDiBuildDriverInfoList(m_DeviceInfoSet, m_DeviceInfoData, m_DriverType);
125 }
126
133 {
134 if (m_result)
135 SetupDiDestroyDriverInfoList(m_DeviceInfoSet, m_DeviceInfoData, m_DriverType);
136 }
137
143 BOOL status() const noexcept
144 {
145 return m_result;
146 }
147
148 protected:
150 HDEVINFO m_DeviceInfoSet;
151 PSP_DEVINFO_DATA m_DeviceInfoData;
152 DWORD m_DriverType;
153 BOOL m_result;
155 };
156
158}
Base abstract template class to support generic object handle keeping.
Definition: Common.h:603
HDEVINFO handle_type
Datatype of the object handle this template class handles.
Definition: Common.h:608
handle_type m_h
Object handle.
Definition: Common.h:854
void attach(handle_type h) noexcept
Sets a new object handle for the class.
Definition: Common.h:817
HDEVINFO wrapper class.
Definition: SetupAPI.h:24
virtual ~setup_device_info_list()
Frees the device information set.
Definition: SetupAPI.h:33
__declspec(deprecated("Use SetupDiCreateDeviceInfoList")) bool create(const GUID *ClassGuid
Creates an empty device information set and optionally associates the set with a device setup class a...
void free_internal() noexcept override
Frees the device information set.
Definition: SetupAPI.h:96
__declspec(deprecated("Use SetupDiGetClassDevsEx")) bool create(const GUID *ClassGuid
Creates a device information set that contains requested device information elements for a local or a...
Builds a list of drivers in constructor and deletes it in destructor.
Definition: SetupAPI.h:106
setup_driver_info_list_builder(HDEVINFO DeviceInfoSet, PSP_DEVINFO_DATA DeviceInfoData, DWORD DriverType) noexcept
Construct the builder and builds a list of drivers that is associated with a specific device or with ...
Definition: SetupAPI.h:116
virtual ~setup_driver_info_list_builder()
Deletes a driver list and destructs the builder.
Definition: SetupAPI.h:132
BOOL status() const noexcept
Return result of SetupDiBuildDriverInfoList() call.
Definition: SetupAPI.h:143
#define WINSTD_NONCOPYABLE(C)
Declares a class as non-copyable.
Definition: Common.h:52
#define WINSTD_NONMOVABLE(C)
Declares a class as non-movable.
Definition: Common.h:60
#define WINSTD_HANDLE_IMPL(C, INVAL)
Implements default constructors and operators to prevent their auto-generation by compiler.
Definition: Common.h:161
static const HDEVINFO invalid
Invalid handle value.
Definition: Common.h:613