3
votes

I trying make small test in vbscript so created very, very simple dll in C#(i am new) and want to use it in vbscript.

C# code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;

namespace myNamespace
{
    public class myClass1
    {
        public string sVariable1="Variable content";
    }

    public class myClass2
    {
        public myClass1 myMethod2(myClass1 test)
        {
            return test;
        }
    }
}

and vbscript

Set oClass1 = CreateObject("myNamespace.myClass1")
Set oClass2 = CreateObject("myNamespace.myClass2")
WScript.Echo oClass1.sVariable1

Set return = oClass2.myMethod2(oClass1)
WScript.Echo return.sVariable1

after running vbscript, on console i have "Variable content" displayed by first echo and next i have error "microsoft vbscript runtime error invalid procedure call or argument: 'oClass2.myMethod2'".

Could I pass object in this way ?

Referring to the note of MK2. Problem is not the return type by method, because following code is working.

        public myClass1 myMethod2()
        {
            myClass1 test = new myClass1();
            return test;
        }

and vbs

Set return = oClass2.myMethod2()

now on console i have

Variable content
Variable content

But how to pass myClass1 object in vbs ?

1
Shouldn't you change this: public myClass1 myMethod2(myClass1 test) to this: public myClass2 myMethod2(myClass1 test) - HK1

1 Answers

0
votes

OK I found solution. In C# as a param myMethod2 I declared ref to object and next I used type casting. Something like this:

    public myClass1 myMethod2(ref object refObject)
    {
        myClass1 test = (myClass1)refObject;
        return test;
    }

Now vbscript working perfectly. I hope it will be helpful for someone :)