为什么创建后无法连接到 COM 对象事件?
我用 C++ 编写了一个 COM 对象。
如果我同时执行这两个操作(Javascript),创建对象并连接到其事件工作正常:
var obj = WScript.CreateObject("SomeCOMClass.Object", "event_");
但是以下会生成此错误(msdn): http://msdn.microsoft.com/en-us/library/a7tya2wc(VS.85).aspx。
var obj = WScript.CreateObject("SomeCOMClass.Object");
WScript.ConnectObject(obj, "event_");
错误描述页面没有描述为什么我无法连接到已创建的对象。 我希望能够连接到创建的对象,因为我计划从各种 C++ COM 函数返回对象。
I have written a COM object using C++.
Creating the object and connecting to its events works fine if I do them both at the same time (Javascript):
var obj = WScript.CreateObject("SomeCOMClass.Object", "event_");
However the following generates this error (msdn): http://msdn.microsoft.com/en-us/library/a7tya2wc(VS.85).aspx.
var obj = WScript.CreateObject("SomeCOMClass.Object");
WScript.ConnectObject(obj, "event_");
The error description page does not describe why I cannot connect to already created objects. I would like to be able to connect to created objects because I plan on returning objects from various C++ COM functions.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我刚刚发现 Eric Lippert 的一篇旧博客文章描述了这一点:
http://blogs.msdn.com/ericlippert/archive/ 2005/02/15/373330.aspx
本质上,他说你需要你的对象实现
IProvideClassInfo
或IProvideMultipleClassInfo
以便 WScript 收集有关 2005/02/15/373330.aspx 的类型信息传出(回调)接口,因此可以设置匹配的处理程序。I just found an old blog post by Eric Lippert describing this:
http://blogs.msdn.com/ericlippert/archive/2005/02/15/373330.aspx
Essentially, he says you need your objects to implement
IProvideClassInfo
orIProvideMultipleClassInfo
in order for WScript to harvest type info about the outgoing (callback) interfaces, so it can set up a matching handler.