views:

240

answers:

1

I'm trying to implement scripting capability to my application. I'm using the code below. Whenever I instantiate a new Api object, the application is supposed to quit (a little testing thing :p)

However, the application crashes at script.AddObject(...) with the error Specified cast is not valid. Is there a step I'm missing here?

public class ApiExposed
{
    public string ModuleName;

    public void Exit()
    {
        System.Environment.Exit(0);
    }
}
public class Api
{
    ScriptControlClass script;
    ApiExposed ApiObj;

    public Api()
    {
        ApiObj = new ApiExposed();

        script = new ScriptControlClass();
        script.Language = "VBScript";
        script.AddObject("tbapi", (object)ApiObj, true);

        script.Eval("tbapi.Exit()");
    }
}
+2  A: 

My guess is, the ApiExposed class is not COM visible - it will need to be in order for VBScript to interact with it.

1800 INFORMATION
I'll look into this
Charlie Somerville
Wonderful - it works perfectly! Thanks.
Charlie Somerville