我想在 VB6 主机上使用 IE9(本机 json,...)中的新 JScript 功能。从我读到的(见http://blogs.msdn.com/b/jscript/archive/2009/04/17/versioning-language-features-in-jscript.aspx),我必须调用IActiveScriptProperty: :SetProperty 并将 SCRIPTPROP_INVOKEVERSIONING 设置为 2 (SCRIPTLANGUAGEVERSION_5_8)。因此,我已将接口添加到我的 odl 文件中:
...
[
odl,
uuid(4954E0D0-FBC7-11D1-8410-006008C3FBFC),
]
interface IActiveScriptProperty : stdole.IUnknown
{
HRESULT GetProperty(
[in] LONG dwProperty,
[in] VARIANT *pvarIndex,
[out] VARIANT *pvarValue
);
HRESULT SetProperty(
[in] LONG dwProperty,
[in] VARIANT *pvarIndex,
[in] VARIANT *pvarValue
);
}
...
在 VB6 主机中,我使用以下命令创建引擎:
Dim hRes as Long
Dim IUnk as IUnknown
Dim clsidJS as UUID
Dim uuidActScr as UUID
Dim IProperty as IActiveScriptProperty
Dim IScript As IActiveScript
Dim IParse As IActiveScriptParse
' Create the engine
CLSIDFromString "{16d51579-a30b-4c8b-a276-0ff4dc41e755}", clsidJS ' JScript9 (Chakra)
CLSIDFromString IID_IActiveScript, uuidActScr
hRes = CoCreateInstance(clsidJS, Nothing, CLSCTX_INPROC_SERVER, uuidActScr, IUnk)
' Set version
Const SCRIPTPROP_INVOKEVERSIONING As Long = &H4000
Dim Version as Variant
Version = 2
Set IProperty = iUnk
IProperty.SetProperty SCRIPTPROP_INVOKEVERSIONING, 0, Version '<--- Here I get error 5 "Invalid procedure call or argument"
在上一篇文章的最后一条评论中,Byron 说: “带有 SCRIPTPTOP_INVOKEVERSIONING 的 SetProperty 的未记录‘特征’是该值必须是 VT_I4 或 VT_I2 - 任何其他整数类型都将被视为无效而被拒绝。”
所以我将上面的代码修改为(VariantType属性来自http://www.xbeat.net/vbspeed/i_OpenODL.htm#VBVM6Lib):
...
Version = 2
VariantType(Version) = VT_I4 ' Force VT_I4 variant type
Set IProperty = iUnk
IProperty.SetProperty SCRIPTPROP_INVOKEVERSIONING, 0, Version '<--- Here I get the same error 5 "Invalid procedure call or argument"
注意:如果我不尝试设置 SCRIPTPROP_INVOKEVERSIONING 属性,引擎工作正常,如果我运行:ScriptEngineMajorVersion() + "." + ScriptEngineMinorVersion() + "." + ScriptEngineBuildVersion() 我得到“9.0.16457”,但我无法以原生 json 的形式访问新功能。
有任何想法吗?
谢谢!