I'm developing a COM Object in C#, Visual studio 2010, .NET 3.5, x86 which I'm using it in a VBA program.
namespace Test
{
[Guid("8b65089f-5d98-41e7-9579-1ee384948e4c")]
[ComVisible(true)]
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct Contact
{
[MarshalAs(UnmanagedType.BStr)]
public string Test1;
public string[] Array;
}
[Guid("8b65082f-5d98-41e7-9579-1ee384948e4e"), ComVisible(true)]
public interface IInContainer
{
Contact[] Contacts { [return: MarshalAs(UnmanagedType.SafeArray, SafeArraySubType = VarEnum.VT_VARIANT)] get; set; }
string[] strings { [return: MarshalAs(UnmanagedType.SafeArray, SafeArraySubType = VarEnum.VT_VARIANT)] get; set; }
}
[Guid("8b65089f-5d98-41e7-9579-1ee384948e4b"), ClassInterface(ClassInterfaceType.AutoDual), ComVisible(true)]
public class InContainer
{
//[MarshalAs(UnmanagedType.BStr)]
public Contact[] Contacts { get;set;}
public string[] strings { get; set; }
}
}
I'm able to see the structure/interface of the object in VB when I create it.
I can change the information in Container.strings from VB without any issue.
However, I cannot change the information in the Contact array (with the Contact structs) via VB.
Lets say the Contact array i 1 long, that node have all values set to "test". When trying to change it via VB i.e. Container.Contact(0).Test1 = "Monkey"
I get no error. When trying to read it directly after i.e. Print(Container.Contact(0).Test1)
I get "", or whatever default string I set.
I'm able to change the information in a contact by using a method on the container object, this is undesirable however.
So I need help why the values are read only in Container.Contact array.