Groups | Blog | Home
all groups > dotnet interop > september 2005 >

dotnet interop : Exposing IEnumerable for COM interop with VB6 - Need help


Bob
9/21/2005 12:00:00 AM
Hi,

I have followed the advice by Adam Nathan in his ".Net and COM - The
Complete Interoperability Guide" to develop a COM component in C# which
exposes the COM enumerator thus exposing the IEnumerable as follows:
[
Guid( "84843982-800D-4B5B-84F3-78173EE1731B" ),
Description("The SimpleServer CoClass"),
ProgId( "SimpleServer.1" ),
ClassInterface( ClassInterfaceType.None ),
ComVisible( true )
]
public class SimpleServer : ISimpleServer
{
private IntList simpleList = new IntList();
public SimpleServer()
{
}

// DISPID_NEWENUM is automatically set for this method.
public IEnumerator GetEnumerator()
{
Debug.WriteLine( "SimpleServer.GetEnumerator()" );
return this.simpleList.GetEnumerator();
}
}

I have left out outer stuff for clarity. This is the server, a strong name
assembly in GAC and registered properly. The TLB checks out fine.

I then use VB6 to test its COM support and in particular the use of FOR
EACH...NEXT construct in VB6.

Accesses to other interface methods from VB6 are fine.

The only problem is when I do this:
Dim svr As SimpleComServer.SimpleServer
On Error GoTo ReportProblem

Set svr = New SimpleComServer.SimpleServer
Dim a
Dim b
Set b = svr.GetEnumerator() ' Fine no error
For Each a In svr.GetEnumerator() '<<-- Problem!!
Debug.Print "Value is " & a
Next

The line For Each ... caused 'Type Mismatch' Error 13 VB6 error. Debug
traces on the C# COM server indicated that the svr.GetEnumerator() was
called and a non-Null IEnumerator returned.

Can someone shed some light on this problem?

Thanks.

Bob

Robert Jordan
9/24/2005 11:39:21 AM
Hi Bob,

[quoted text, click to view]

You must implement IEnumerable as well, otherwise no
IEnumVARIANT wrapper will be generated:

public class SimpleServer : ISimpleServer, IEnumerable

Your GetEnumerator looks fine, so just enlisting IEnumerable
should do the job.

AddThis Social Bookmark Button