返回E_FAILED时互操作抛出comexception [英] Interop throw comexception when E_FAILED is returned
问题描述
我在托管c#应用程序中使用COM对象.在某些情况下,COM对象可能返回E_FAILED状态,并使用故障详细信息填充属性.在这种情况下,引用com对象时创建的互操作会转换E_FAILED 到comexception并且其他属性未填充(空)甚至不可访问(在抛出ComException后访问它会导致另一个ComException).请告知tx Oren
Im using a COM object within a managed c# application. In some cases the COM object might return E_FAILED status and populate anothe property with the failure details. In such a case the interop created when the com object is referenced translate the E_FAILED to comexception and the other property is not populated (empty) or even not accessible (accessing it after the ComException is thrown causes another ComException) Please advise tx Oren
推荐答案
我认为这是正确的……错误HRESULT会自动转换为异常.相当典型的VB(经典)和许多其他语言也可以通过这种方式进行处理.
I think this is correct... an error HRESULT is automatically translated into an exception. Pretty typical, VB (classic) and many other languages treat it this way too.
您需要使用尝试/捕获"进行包装.
You need to wrap with a Try/Catch.
>并且其他属性未填充
> and the other property is not populated
听起来像COM对象实现中的问题.
Sounds like a problem in the COM object implementation.
这篇关于返回E_FAILED时互操作抛出comexception的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!