收到COMException在C#中,当挂接到事件 [英] COMException in C# when hooking into event

查看:838
本文介绍了收到COMException在C#中,当挂接到事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到一个COM异常试图挂钩到的COM对象的事件时。这里是code我试图执行。

I am receiving a COM Exception when trying to hook into an event on a COM Object. Here is the code I am trying to execute.

COMClass A = IComClass为ComClass;
a.SomeEvent + =新SomeEvent_EventHandler(MethodNameHere);

COMClass a = IComClass as ComClass;
a.SomeEvent += new SomeEvent_EventHandler(MethodNameHere);

两线抛出一个异常类型收到COMException的以下信息:

Line two throws an exception of type COMException with the following information:

System.Runtime.InteropServices.COMException被抓获

System.Runtime.InteropServices.COMException was caught

消息=从HRESULT异常:0x80040202

Message="Exception from HRESULT: 0x80040202"

来源=mscorlib程序

Source="mscorlib"

错误code = -2147220990

ErrorCode=-2147220990

堆栈跟踪:        在System.Runtime.InteropServices.ComTypes.IConnectionPoint.Advise(对象pUnkSink,的Int32和放大器; pdwCookie)

StackTrace: at System.Runtime.InteropServices.ComTypes.IConnectionPoint.Advise(Object pUnkSink, Int32& pdwCookie)

有没有人有,为什么我不能挂钩到一个COM事件或是否有解决方法挂钩到COM事件?

Does anyone have any ideas why I am unable to hook into a COM event or if there is a workaround for hooking into COM events?

克里斯

推荐答案

你得到了错误code是CONNECT_E_CANNOTCONNECT,一些Google的好。这表明,COM服务器不开心你尝试订阅事件处理程序。为什么这是不值得的,你需要了解一下。从组件作者或供应商获取帮助几乎总是必需的。

The error code you got is CONNECT_E_CANNOTCONNECT, something that Googles well. It indicates that the COM server isn't happy about your attempt to subscribe an event handler. Why it is not is something you'll need to find out. Getting help from the component author or vendor is almost always required.

有一件事你可以尝试是看与OLEView.exe这类类型库,并找出如果你想订阅的事件上被标记为默认源接口调度接口。如果不是,尝试铸造对象的调度接口类型,则订阅其事件

One thing you can try is to look at the type library with Oleview.exe and find out if the event you're trying to subscribe to is on a dispinterface that's marked as the default source interface. If it is not, try casting the object to the dispinterface type, then subscribe to its event.

这篇关于收到COMException在C#中,当挂接到事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆