I want to use the new JScript features in IE9 (native json, ...) from a VB6 Host. From what I've read (see http://blogs.msdn.com/b/jscript/archive/2009/04/17/versioning-language-features-in-jscript.aspx), I have to invoke the IActiveScriptProperty::SetProperty and set SCRIPTPROP_INVOKEVERSIONING to 2 (SCRIPTLANGUAGEVERSION_5_8). So, I have added the interface to my odl file:
...
[
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
);
}
...
In the VB6 host, I create the engine with:
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"
In the last comment of the previous article, Byron says: "The undocumented 'feature' of the SetProperty with SCRIPTPTOP_INVOKEVERSIONING is that the value must be a VT_I4 or VT_I2 - any other integer type will be rejected as invalid."
So I modify the above code to (VariantType property comes from 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"
NOTE: If I don't try to set SCRIPTPROP_INVOKEVERSIONING property, the engine works ok and if I run: ScriptEngineMajorVersion() + "." + ScriptEngineMinorVersion() + "." + ScriptEngineBuildVersion() I get "9.0.16457', but I don't have access to the new features as native json.
Any ideas?
Thanks!