I have a Com-Visible -Net-Assembly which I want to use from VBScript. Most things works fine except one property thats returns a string[]
to VBS.
The interface:
[Guid("25267107-CFD3-4A1B-8D94-639A7F189C0B"),
InterfaceType(ComInterfaceType.InterfaceIsDual),
ComVisible(true)]
public interface IComMethods : IDisposable
{
string[] Interlockings { get; }
}
The implementation:
public string[] Interlockings
{
get
{
return new string[] { "abc", "def" };
}
}
The VBScript-Client:
Set mms2spc = CreateObject("Promess.mms2spc.ComMethods")
Dim testLCodes : testLCodes = mms2spc.Interlockings
If Not isEmpty(testLCodes) Then
If isArray(testLCodes) Then
Dim iCount : iCount = Ubound(testLCodes) + 1
Stop
For iLCode = 0 To Ubound(testLCodes)
sTextInterlock = testLCodes(iLCode)
Next
End If
End If
However, when I try to use this in VBScript I see the Strings comming as an Array but I cannot access the elements. You can see this when looking at the debugger - every (n)-access gives Empty:
I think the marshalling from C# from VBS is wrong so I added an attribute but that doens't change anything:
public string[] Interlockings
{
[return: MarshalAs(UnmanagedType.SafeArray, SafeArraySubType = VarEnum.VT_BSTR)]`
get{return new string[] { "abc", "def" };}
}
As a workaround I can declare everything in C# as object. That way it works in VBS but thats kind of awkward to me. So how to get this string[] to VBS?