From d4a7a79ace02c3b1e25849b8a5ea9e29a2a6c264 Mon Sep 17 00:00:00 2001 From: Diederick Niehorster Date: Fri, 14 May 2021 21:00:39 +0200 Subject: [PATCH] Add fallback for getting device path. --- source/dshow-base.hpp | 1 + source/dshow-enum.cpp | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/source/dshow-base.hpp b/source/dshow-base.hpp index 5e90f8d..04313e7 100644 --- a/source/dshow-base.hpp +++ b/source/dshow-base.hpp @@ -28,6 +28,7 @@ #include #include #include +#include #include "ComPtr.hpp" #include "CoTaskMemPtr.hpp" diff --git a/source/dshow-enum.cpp b/source/dshow-enum.cpp index 9dc104f..3205038 100644 --- a/source/dshow-enum.cpp +++ b/source/dshow-enum.cpp @@ -473,6 +473,30 @@ static bool EnumDevice(const GUID &type, IMoniker *deviceInfo, } propertyData->Read(L"DevicePath", &devicePath, NULL); + if (!devicePath.bstrVal) { + /* fall back to another method to get device path */ + LPMALLOC co_malloc = nullptr; + hr = CoGetMalloc(1, &co_malloc); + if (FAILED(hr)) + return true; + + ComPtr bind_ctx = nullptr; + hr = CreateBindCtx(0, &bind_ctx); + if (FAILED(hr)) + return true; + + LPOLESTR olestr = nullptr; + bool success = true; + hr = deviceInfo->GetDisplayName(bind_ctx, nullptr, &olestr); + if (SUCCEEDED(hr)) { + hr = InitVariantFromString(olestr, &devicePath); + if (FAILED(hr)) + success = false; + } + co_malloc->Free(olestr); + if (!success) + return true; + } hr = deviceInfo->BindToObject(NULL, 0, IID_IBaseFilter, (void **)&filter);