CSharp and MsScriptControl


Author: 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)

 
Leave Comment:
Name:
Email: (not shown)
Message: (Required)
Math Question: 26 + 91 = ? followed by the letter: S 



About Me
More Blogs
Main Site
Posts: (All)
2020 ( 2 )
2019 ( 5 )
2018 ( 6 )
2017 ( 6 )
2016 ( 22 )
2015 ( 16 )
2014 ( 25 )
2013 ( 4 )
2012 ( 10 )
2011 ( 7 )
2010 (11)
     Dll Not Found in IDE
     Advanced MSScript Control
     random tip
     Clipart / Vector Art
     VB6 Callback from C#
     Binary data from VB6 to C#
     CSharp and MsScriptControl
     HexDumper functions
     Js Beautify From VB6 or C#
     vb6 FormPos
     Inline Asm w VB6
2009 (3)
     The .NET Fiasco
     One rub on computers
     Universal extractor