SetupAPI.h
/*
SPDX-License-Identifier: MIT
Copyright © 1991-2022 Amebis
Copyright © 2016 GÉANT
*/
#pragma once
#include "Common.h"
#include <SetupAPI.h>
namespace winstd
{
class setup_device_info_list : public handle<HDEVINFO, INVALID_HANDLE_VALUE>
{
WINSTD_HANDLE_IMPL(setup_device_info_list, INVALID_HANDLE_VALUE)
public:
virtual ~setup_device_info_list()
{
if (m_h != invalid)
free_internal();
}
bool create(
_In_opt_ const GUID * ClassGuid,
_In_opt_ HWND hwndParent) noexcept
{
handle_type h = SetupDiCreateDeviceInfoList(ClassGuid, hwndParent);
if (h != invalid) {
attach(h);
return true;
}
else
return false;
}
bool create(
_In_opt_ const GUID * ClassGuid,
_In_opt_ PCTSTR Enumerator,
_In_opt_ HWND hwndParent,
_In_ DWORD Flags,
_In_opt_ HDEVINFO DeviceInfoSet,
_In_opt_ PCTSTR MachineName,
_Reserved_ PVOID Reserved) noexcept
{
handle_type h = SetupDiGetClassDevsEx(ClassGuid, Enumerator, hwndParent, Flags, DeviceInfoSet, MachineName, Reserved);
if (h != invalid) {
attach(h);
return true;
}
else
return false;
}
protected:
void free_internal() noexcept override
{
SetupDiDestroyDeviceInfoList(m_h);
}
};
class setup_driver_info_list_builder
{
WINSTD_NONCOPYABLE(setup_driver_info_list_builder)
WINSTD_NONMOVABLE(setup_driver_info_list_builder)
public:
setup_driver_info_list_builder(
_In_ HDEVINFO DeviceInfoSet,
_Inout_opt_ PSP_DEVINFO_DATA DeviceInfoData,
_In_ DWORD DriverType) noexcept :
m_DeviceInfoSet (DeviceInfoSet),
m_DeviceInfoData(DeviceInfoData),
m_DriverType (DriverType)
{
m_result = SetupDiBuildDriverInfoList(m_DeviceInfoSet, m_DeviceInfoData, m_DriverType);
}
virtual ~setup_driver_info_list_builder()
{
if (m_result)
SetupDiDestroyDriverInfoList(m_DeviceInfoSet, m_DeviceInfoData, m_DriverType);
}
BOOL status() const noexcept
{
return m_result;
}
protected:
HDEVINFO m_DeviceInfoSet;
PSP_DEVINFO_DATA m_DeviceInfoData;
DWORD m_DriverType;
BOOL m_result;
};
}
winstd::handle
Base abstract template class to support generic object handle keeping.
Definition: Common.h:604
winstd::handle< HDEVINFO, INVALID_HANDLE_VALUE >::handle_type
HDEVINFO handle_type
Datatype of the object handle this template class handles.
Definition: Common.h:609
winstd::handle< HDEVINFO, INVALID_HANDLE_VALUE >::m_h
handle_type m_h
Object handle.
Definition: Common.h:855
winstd::handle< HDEVINFO, INVALID_HANDLE_VALUE >::attach
void attach(handle_type h) noexcept
Sets a new object handle for the class.
Definition: Common.h:818
winstd::setup_device_info_list
HDEVINFO wrapper class.
Definition: SetupAPI.h:24
winstd::setup_device_info_list::create
bool create(const GUID *ClassGuid, HWND hwndParent) noexcept
Creates an empty device information set and optionally associates the set with a device setup class a...
Definition: SetupAPI.h:48
winstd::setup_device_info_list::~setup_device_info_list
virtual ~setup_device_info_list()
Frees the device information set.
Definition: SetupAPI.h:33
winstd::setup_device_info_list::free_internal
void free_internal() noexcept override
Frees the device information set.
Definition: SetupAPI.h:94
winstd::setup_device_info_list::create
bool create(const GUID *ClassGuid, PCTSTR Enumerator, HWND hwndParent, DWORD Flags, HDEVINFO DeviceInfoSet, PCTSTR MachineName, PVOID Reserved) noexcept
Creates a device information set that contains requested device information elements for a local or a...
Definition: SetupAPI.h:70
winstd::setup_driver_info_list_builder
Builds a list of drivers in constructor and deletes it in destructor.
Definition: SetupAPI.h:104
winstd::setup_driver_info_list_builder::setup_driver_info_list_builder
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:114
winstd::setup_driver_info_list_builder::~setup_driver_info_list_builder
virtual ~setup_driver_info_list_builder()
Deletes a driver list and destructs the builder.
Definition: SetupAPI.h:130
winstd::setup_driver_info_list_builder::status
BOOL status() const noexcept
Return result of SetupDiBuildDriverInfoList() call.
Definition: SetupAPI.h:141
WINSTD_NONCOPYABLE
#define WINSTD_NONCOPYABLE(C)
Declares a class as non-copyable.
Definition: Common.h:53
WINSTD_NONMOVABLE
#define WINSTD_NONMOVABLE(C)
Declares a class as non-movable.
Definition: Common.h:61
WINSTD_HANDLE_IMPL
#define WINSTD_HANDLE_IMPL(C, INVAL)
Implements default constructors and operators to prevent their auto-generation by compiler.
Definition: Common.h:162
winstd::handle< HDEVINFO, INVALID_HANDLE_VALUE >::invalid
static const HDEVINFO invalid
Invalid handle value.
Definition: Common.h:614