summaryrefslogtreecommitdiff
path: root/Source/Core/Common/WindowsDevice.cpp
diff options
context:
space:
mode:
authorJordan Woyak <jordan.woyak@gmail.com>2025-10-14 22:39:17 -0500
committerJordan Woyak <jordan.woyak@gmail.com>2025-11-04 22:51:26 -0600
commit5e65536376ab4b2085cb34a69c6d01bb7fbf9ea8 (patch)
tree5524e89ca3f3de120e7e7f85c08611f0d13b6567 /Source/Core/Common/WindowsDevice.cpp
parent2170080f5355fa7f808a22b58e7ff67d0b89edc8 (diff)
WindowsDevice: Add GetDeviceInterfaceList function and NullTerminatedStringList template.
Diffstat (limited to 'Source/Core/Common/WindowsDevice.cpp')
-rw-r--r--Source/Core/Common/WindowsDevice.cpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/Source/Core/Common/WindowsDevice.cpp b/Source/Core/Common/WindowsDevice.cpp
index 405ea5e25b..9102f24b93 100644
--- a/Source/Core/Common/WindowsDevice.cpp
+++ b/Source/Core/Common/WindowsDevice.cpp
@@ -83,6 +83,36 @@ std::optional<std::wstring> GetDeviceInterfaceStringProperty(LPCWSTR iface,
DEVPROP_TYPE_STRING);
}
+NullTerminatedStringList<WCHAR> GetDeviceInterfaceList(LPGUID iface_class_guid, DEVINSTID device_id,
+ ULONG flags)
+{
+ while (true)
+ {
+ ULONG list_size = 0;
+ const auto size_result =
+ CM_Get_Device_Interface_List_Size(&list_size, iface_class_guid, device_id, flags);
+ if (size_result != CR_SUCCESS || list_size == 0)
+ list_size = 1;
+
+ auto buffer = std::make_unique_for_overwrite<WCHAR[]>(list_size);
+ const auto list_result =
+ CM_Get_Device_Interface_List(iface_class_guid, device_id, buffer.get(), list_size, flags);
+
+ // "A new device can be added to the system causing the size returned to no longer be valid."
+ // Microsoft recommends trying again in a loop.
+ if (list_result == CR_BUFFER_SMALL)
+ continue;
+
+ if (list_result != CR_SUCCESS)
+ {
+ ERROR_LOG_FMT(COMMON, "CM_Get_Device_Interface_List: {}", list_result);
+ buffer[0] = 0;
+ }
+
+ return {std::move(buffer)};
+ }
+}
+
} // namespace Common
#endif