Discussion:
Adding persistent global property to IActiveScript
(too old to reply)
Nathan Baker
2007-02-09 17:56:16 UTC
Permalink
Hello,

I have created a scripting environment in C# using Active Scripting. I
have the following code:
_script = new ScriptHost();
JScript jsengine = new JScript();
IActiveScriptParse asp = jsengine as IActiveScriptParse;
IActiveScript ias = jsengine as IActiveScript;

asp.InitNew();
ias.SetScriptSite(_script);
stdole.EXCEPINFO einfo;

ias.AddNamedItem("test", SCRIPTITEM_ISVISIBLE |
SCRIPTITEM_GLOBALMEMBERS);
asp.ParseScriptText("test.DoIt();");

ias.Close();

The implementation of test.DoIt() simply displays a message box:
public class TestClass {
public void DoIt() {
MessageBox.Show("I live!");
}
}

The GetItemInfo method of _script is as follows:
public void GetItemInfo(string pstrName, uint dwReturnMask, out object
ppiunkItem, IntPtr ppti)
{
ppiunkitem = null;
ppti = IntPtr.Zero;
if (pstrName == "test") {
ppiunkItem = new TestClass();
if(ppti != IntPtr.Zero) {
Marshal.WriteIntPtr(ppti,
Marshal.GetITypeInfoForType(ppiunkItem.GetType()));
}
}
}

Rather than displaying a message box (as expected), the call to
asp.ParseScriptText does nothing. Why is this?

Thanks,
Nathan
Nathan Baker
2007-02-12 19:01:14 UTC
Permalink
Got it working.

For posterity, the call to asp.ParseScriptText should read:

asp.ParseScriptText("test.DoIt();", null, IntPtr.Zero, null, 0, 0,
SCRIPTITEM_ISVISIBLE, IntPtr.Zero, out einfo);

And then after this call, you need to tell the script to compile and
run:
ias.SetScriptState(2);
This was the magic word I was missing...

Nathan

Loading...