Return byte array from C# to VBScript via COM inte

2019-08-11 17:15发布

问题:

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

回答1:

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