CSharp and MsScriptControlAuthor: Dave Date: 08.23.10 - 6:15pm Even this took some fussing and searching to get the tricks figured out... using System; using System.Collections.Generic; using System.Linq; using System.Text; using MSScriptControl; //class test has to support IDispatch to AddObject() [assembly: System.Runtime.InteropServices.ComVisible(true)] namespace ConsoleApplication1 { public class test{ public int b(int y) { return y + 1; } public object c() { return this; } } class Program { public static MSScriptControl.ScriptControl sc = new ScriptControl(); static void Main(string[] args) { test t = new test(); object ret; sc.Language = "jScript"; sc.AddObject("test", t,true); sc.AddCode("function a(y){ return y+100;}"); //works in IE not here why? ex: d().e(4) = 14 //sc.AddCode("function d(){this.e = f; return this;};" + // "function f(x){return x+10};"); Console.WriteLine("test.b(1) = " + sc.Eval("test.b(1)") ); ret = sc.Eval("test.c()"); Console.WriteLine("test.c() = " + ret + " Hash:" + ret.GetHashCode() +" =? t.hash: " + t.GetHashCode() ); Console.WriteLine("a(10) = " + sc.Eval("a(10)")); Console.ReadKey(); return; } } } Comments: (0) |
About Me More Blogs Main Site
|
||||||||||||||||||||||||||||||