如何获取具有已知类 ID 的设备名字?

发布于 2024-08-23 18:50:46 字数 751 浏览 5 评论 0原文

我正在使用 DirectShowLib,它是 DirectShow 的薄包装。 我已成功枚举 BDA 设备并收集其 CLSID。现在,当用户按名称选择设备并且我知道所选的 CLSID 时,我需要将此设备添加到我的过滤器图表中。

我做了以下事情:

Type type = Type.GetTypeFromCLSID(classid);
object device = Activator.CreateInstance(type);

现在的问题是 - 我在设备中得到了什么样的对象?调试器显示它是一个有效的 Com 对象。如果我尝试将其转换为 IBaseFilter,则会收到异常“不支持此类接口”。我可以成功将其投射到 IMoniker。但是,如果我尝试执行以下操作:

int hr = graphBuilder.AddSourceFilterForMoniker(
    device, null, filtername, out receivedFilter);

我收到错误:

HRESULT: 0x800401e4 (2147746276)
Name: MK_E_SYNTAX

我知道如果我在枚举后立即使用方法 AddSourceFilterForMoniker 则可以正常工作,所以看来我只是没有正确创建名字对象。

如果类 id 已知,那么创建名字对象的正确方法是什么,以便我可以将其传递给 AddSourceFilterForMoniker?

I am using a DirectShowLib which is a thin wrapper for DirectShow.
I have successfully enumerated BDA devices and collected their CLSIDs. Now when user selects a device by name and I know the chosen CLSID, I need to add this device to my filter graph.

I did the following:

Type type = Type.GetTypeFromCLSID(classid);
object device = Activator.CreateInstance(type);

Now the question is - what kind of object I got here in device? Debugger shows that it is a valid Com object. If I try to cast it to IBaseFilter, I get an exception "No such interface supported". I can cast it to IMoniker successfully. But then if I try to do the following:

int hr = graphBuilder.AddSourceFilterForMoniker(
    device, null, filtername, out receivedFilter);

I get an error:

HRESULT: 0x800401e4 (2147746276)
Name: MK_E_SYNTAX

I know that the method AddSourceFilterForMoniker works fine if I use it right after enumeration, so it seems I just do not create the moniker right.

What is the right way to create moniker object if class id is known, so I can pass it to the AddSourceFilterForMoniker?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

挽心 2024-08-30 18:50:46

只是猜测,但您似乎没有创建 IBindCtx实施。我所涉及的所有涉及 IMoniker 的操作可见,需要传递 IBindCtx 实现,以便为涉及名字的操作提供上下文。

话虽这么说, AddSourceFilterForMoniker 方法不是不同的是,您没有传递名字的绑定上下文。

Just a guess, but it appears you are not creating an IBindCtx implementation. All operations that involve IMoniker that I've seen require a IBindCtx implementation to be passed in order to provide context for operations involving the moniker.

That being said, the AddSourceFilterForMoniker method is no different, in that you aren't passing a bind context for the moniker.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文