views:

28

answers:

1

I have a Class Library that is exposed to COM like this:

<ComClass(SomeClass.ClassId, SomeClass.InterfaceId, SomeClass.EventsId)>
Public Class SomeClass

    Public Const ClassId As String = "GUID1"
    Public Const InterfaceId As String = "GUID2"
    Public Const EventsId As String = "GUID3"

    Public Sub SomeMethod(ByVal ParamArray values() As Object)
        ''//Some Code Here    
    End Sub
End Class

I then used regasm /tlb /codebase to to register it. All methods and properties seem to work correctly in VBA/VB6 but when I try to access the Method with a ParamArray it won't event compile. I get the error:

Compile error:

Function or interface marked as restricted, or the function uses an Automation type not suppport in Visual Basic.

What do I need to do to properly expose this Method so I can use it like this?:

SomeClass.SomeMethod 1, 2, 3
+2  A: 

the function uses an Automation type not supported in Visual Basic.

The buck stops there, there is no equivalent of parameter arrays in VB6. Drop the ParamArray keyword. The VB6 code has to pass an array of Variants. Unpleasant, consider redesigning your class.

Hans Passant
Hello again Obi Wan:) There are paramarrays in VB6/VBA but they are byref variant arrays instead of byval object arrays. Is this the reason for the incompatability?
Oorang
Seems a pity if this is true. You could create COM components in VB6 that accepted parameter arrays but they had to be arrays of variants, like this `Public Sub SomeMethod(ParamArray values() As Variant)`. You would hope the COM interop stuff would be able to map a VB.Net ParamArray into something VB6 could call. http://msdn.microsoft.com/en-us/library/aa266305(v=VS.60).aspx
MarkJ
Variant == object. I don't remember this clearly, don't have VB6 docs anymore. Gotta jump start an old machine, I remember banging my knee cap on it about a year ago. Later.
Hans Passant
If variant==object then maybe it will work if you make it byref, Oorang, like you suggested. BTW VB6 docs are online, with some small omissions. http://msdn.microsoft.com/en-us/library/aa314411%28VS.60%29.aspx
MarkJ
@MarkJ, I did give that a try but it seems that in VB.Net ParamArrays are *required* to be ByVal.
Oorang
@Oorang. Ouch. @Hans: OK, +1, you're right.
MarkJ