Share via


How do you return a C# struct to a VB6 calling program??? (Good ol' COM Interop) :-|

I've beaten my head against the wall time and again over the weekend, and still haven't been able to figure it out.

Returnin a string or an int isn't a problem, but when I try to return a struct that consists of a couple of string fields, you'd think I was calling BillG an open source lover by the way the VB6 compiler reacts.

Yes, I've run GACUTIL, TLBEXP, and REGASM.  Here's my C# struct definition:

 [Guid("68F1676C-B813-45bf-8155-1FF10A66510F")]
[StructLayout(LayoutKind.Sequential)]
   public struct EmpData
   {
     public string field1;
     public string field2;
     public string field3;
   }

Yes, the [StructLayout] attribute is redundant, since it's the default for C# and VB .NET, but hey, I'm desperate.  (And I have tried it with and without the [Guid] attribute in front of the struct.  Same result.)

And here's my VB6 Type definition:

    Private Type t
      field1 As String
      field2 As String
      field3 As String
   End Type

When I make the VB6 project, I get a compile error on this line:

     eData = emp.ReturnEmpData()

“eData” is declared as “Dim eData As t“ and “emp” is an instance of the C# class.  ReturnEmpData() returns the EmpData struct from the C# program.

The “make” error message is: “Variable uses an Automation type not supported in Visual Basic.”

I've checked in MSDN, newsgroups, Don Box's “Essential .NET” book.  Nothing seems to fit.  (I may just be exposing my ignorance.  Heh.)

Anyone know how to make this work?

Thanks,
bliz