DISPID_VALUE 对于从脚本调用 IDispatch 是否可靠? [英] is DISPID_VALUE reliable for invokes on IDispatchs from scripts?

查看:21
本文介绍了DISPID_VALUE 对于从脚本调用 IDispatch 是否可靠?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

继续这个问题,我很困惑是否IDispatch::Invoke() 上的 >DISPID_VALUE 用于脚本函数和属性(在我的例子中是 JavaScript)可以被认为是调用由 表示的实际函数的标准和可靠的IDispatch?
如果是,在 MSDN 中的任何地方都提到过吗?

Continuing from this question, i am confused whether DISPID_VALUE on IDispatch::Invoke() for script functions and properties (JavaScript in my case) can be considered standard and reliable for invoking the actual function that is represented by the IDispatch?
If yes, is that mentioned anywhere in MSDN?

请注意,问题是关于这种行为是否可以预期,而不是我无法提前知道的某些界面可能是什么样子.

Please note that the question is about if that behaviour can be expected, not what some interfaces i can't know in advance might look like.

一个简单的用例是:

// usage in JavaScript
myObject.attachEvent("TestEvent", function() { alert("rhubarb"); }); 

// handler in ActiveX, MyObject::attachEvent(), C++
incomingDispatch->Invoke(DISPID_VALUE, IID_NULL, LOCALE_SYSTEM_DEFAULT,
                         DISPATCH_METHOD, par, res, ex, err);

试图澄清问题.

推荐答案

如果脚本定义一致,则从脚本调用对象应该是可靠的.这应该是 MSHTML 中的 JScript/Javascript 的情况,但不幸的是,关于这个主题的文档真的很少,我手头没有任何可靠的证据.

It should be reliable for invokes on objects from scripts if the script defines it consistently. This should be the case for JScript/Javascript in MSHTML, but unfortunately there is really sparse documentation on the subject, I don't have any solid proof in-hand.

根据我自己的经验,传递给 attachEvent() 的 Javascript 函数应该始终保持一致——接收到的函数"对象只能有一个与其自身匹配的可调用方法.因此,默认方法是您可以找到的唯一方法,DISPID 为 0.Javascript 函数通常没有成员函数,尽管我确信有一种方法可以做到这一点.如果它确实有成员函数,您会以与对象上的成员函数相同的方式看待它们.根据 expando 函数的规则,JScript 中的成员函数对于 IDispatchEx 将始终保持一致,因为任何添加到对象的函数都算作 expandos.

In my own experience, a Javascript function passed to attachEvent() should always be consistent- an object received that is a 'function' can only have one callable method that matches itself. Hence the default method is the only one you can find, with DISPID 0. Javascript functions don't ordinarily have member functions, although i'm sure there is a way for this to be possible. If it did have member functions, you would see them the same way as member functions on objects. Member functions in JScript will always be consistent with regard to IDispatchEx, according to the rules of expando functions, as any functions added to an object count as expandos.

IDispatchEx 接口@MSDN

这篇关于DISPID_VALUE 对于从脚本调用 IDispatch 是否可靠?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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