如何从使用 tlbimp.exe 导入到 c# 的库中获取 HRESULT 返回?

发布于 2024-09-15 09:13:38 字数 1135 浏览 4 评论 0原文

我正在使用 c# 中的 GMFBridge directshow 过滤器,导入库似乎丢弃了 HRESULT。 ie

[id(5), helpstring("Create render filters in empty render graph")]
HRESULT CreateRenderGraph(
  [in] IUnknown* pSourceGraphSinkFilter,
  [in] IUnknown* pRenderGraph,
  [out, retval] IUnknown** pRenderGraphSourceFilter);

[id(6), helpstring("Connect two graphs")]
HRESULT BridgeGraphs(
  [in] IUnknown* pSourceGraphSinkFilter,
  [in] IUnknown* pRenderGraphSourceFilter);

被翻译(由 midl.exe 和 tlbimp.exe)为:

[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime), DispId(5)]
object CreateRenderGraph([In, MarshalAs(UnmanagedType.IUnknown)] object pSourceGraphSinkFilter, [In, MarshalAs(UnmanagedType.IUnknown)] object pRenderGraph);

[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime), DispId(6)]
void BridgeGraphs([In, MarshalAs(UnmanagedType.IUnknown)] object pSourceGraphSinkFilter, [In, MarshalAs(UnmanagedType.IUnknown)] object pRenderGraphSourceFilter);

我导入的其他 COM 库将返回值翻译为输出参数,并保留原始 COM 方法的 HRESULT 返回值。为什么这个库的行为不同?是否有可能强迫其他行为?

谢谢, 安迪

I am using the GMFBridge directshow filter from c# and the import library seems to discard the HRESULTs. i.e

[id(5), helpstring("Create render filters in empty render graph")]
HRESULT CreateRenderGraph(
  [in] IUnknown* pSourceGraphSinkFilter,
  [in] IUnknown* pRenderGraph,
  [out, retval] IUnknown** pRenderGraphSourceFilter);

[id(6), helpstring("Connect two graphs")]
HRESULT BridgeGraphs(
  [in] IUnknown* pSourceGraphSinkFilter,
  [in] IUnknown* pRenderGraphSourceFilter);

is translated (by midl.exe and tlbimp.exe) into:

[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime), DispId(5)]
object CreateRenderGraph([In, MarshalAs(UnmanagedType.IUnknown)] object pSourceGraphSinkFilter, [In, MarshalAs(UnmanagedType.IUnknown)] object pRenderGraph);

[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime), DispId(6)]
void BridgeGraphs([In, MarshalAs(UnmanagedType.IUnknown)] object pSourceGraphSinkFilter, [In, MarshalAs(UnmanagedType.IUnknown)] object pRenderGraphSourceFilter);

Other COM libraries I have imported translate returned values as out parameters and preserve the HRESULT return value of the original COM method. Why does this library behave differently? Is it possible to force the other behaviour?

Thanks,
Andy

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

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

发布评论

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

评论(1

你丑哭了我 2024-09-22 09:13:38

.NET 约定是将 [out, retval] 转换为 C# 返回值,并将失败的 HRESULT 转换为 COMException 对象,HRESULT 位于 ErrorCode 属性中。我认为如果您想查看非错误 HRESULT,您就会陷入困境。

我有兴趣查看翻译后生成原始 HRESULT 的方法的 IDL 声明 - 您问题中的示例是我通常期望看到的。

The .NET convention is to turn [out, retval] into a C# return value, and turn failure HRESULTs into COMException objects, with the HRESULT in the ErrorCode property. I think you're stuck if you want to see non-error HRESULTs.

I'd be interested to see the IDL declarations of the methods that produced raw HRESULTs after translation - the example in your question is what I'd expect to see normally.

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