如何从使用 tlbimp.exe 导入到 c# 的库中获取 HRESULT 返回?
我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
.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 intoCOMException
objects, with the HRESULT in theErrorCode
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.