views:

851

answers:

1

Hey all,

I have C# method that returns a byte array I want to be able to access from VBScript. More or less:

namespace ClassLibrary7
{
    [ClassInterface(ClassInterfaceType.AutoDual)]
    [Guid("63A77D29-DB8C-4733-91B6-3CC9C2D1340E")]
    [ComVisible(true)]
    public class Class1
    {
        public void Create(
            out byte[] BinaryData
            )
        {
            // do some work and return BinaryData
            BinaryData = new byte[] { 1, 2, 3, 4 };
        }
     }
 }

and the vbscript to look like:

dim o
dim b

set o = wscript.CreateObject("ClassLibrary7.Class1")

o.Create b

MsgBox ubound(b)

I'm lost. Google doesn't want to cooperate... and I'm hoping someone here can help!

Rob

A: 

This should help:

COM Interop Part 2: C# Server Tutorial
http://msdn.microsoft.com/en-us/library/aa645738(VS.71).aspx

and this:

Creating a COM server with .NET. C#
http://codebetter.com/blogs/peter.van.ooijen/archive/2005/08/02/130157.aspx

Robert Harvey
The problem was that to return a byte array to SBCcript you're dealing with how VBScript... which is through variant reference. With interop it turns out that specifying "object" for the data type solves the problem. Eg. public void Create(out object BinaryData);
That makes sense.
Robert Harvey