I have an enum defined in managed code, e.g.:
public enum MyEnum
{
MyValue1,
MyValue2,
MyValue3
}
I have exposed a method which takes an array of MyEnum as an argument, e.g.:
public void MyMethod([In] ref MyEnum[] values)
{
...
}
And now I attempt to call this method from VB6 code as follows:
Dim myValues(0 To 2) As MyEnum
myValues(0) = MyEnum_MyValue1
myValues(1) = MyEnum_MyValue2
myValues(2) = MyEnum_MyValue3
Set obj = ... ' Instantiate .NET class
obj.MyMethod myValues
When I do this, I get an error at the line "obj.MyMethod myValues" as follows:
-2146233037 (80131533)
Specified array was not of the expected type
Why is this and is there a way I can marshal an array of Enums?
The generated typelib looks like I would expect it to, i.e. the argument is
[in] SAFEARRAY(MyEnum)* values
TDC - 05 Oct 2005 13:48 GMT
VB6 only does in-out arrays. You'll need to declare that method as
ByRef (or ref I think it is in C#).
Tom
Joe - 05 Oct 2005 20:45 GMT
TDC,
Thanks for responding. I am already declaring the array argument as ByRef -
the keyword is ref in C# - the method signature is as follows:
public void MyMethod([In] ref MyEnum[] values)
Without declaring the array as ref, I get a different error, but this
applies to any array not just arrays of Enums.
Any other ideas?
> VB6 only does in-out arrays. You'll need to declare that method as
> ByRef (or ref I think it is in C#).
>
> Tom