How do I pass a C# ArrayList to a method that takes a MFC CList?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am importing a visual 6 C++ dll into C#. The methods in the dll take a CList type and I was wondering what type in C# can I use that correctly matches the CList type. Is the ArrayList type in C# comparable or should I just create my own List type in C#?
 
Hmmmm,

I doubt that this will be simple...

CList is not a COM object and it is not a C style array;
it is a C++ template class that implements a doubly linked
list. Because CList is a template class you won't be able
to do something exceedingly slick, like create a custom
MasrshalAs attribute for CList classes, because the .NET
framework doesn't support templates <yet>.

So if I were you I would:

1) Check around to see if M$ or a third party has
some "MFC .NET interoperability" support classes that will
help with CList and then pray that they work...

2) Failing that, consider the painful option of wrapping
the VS 6.0 DLL behind another VS 6.0 DLL that exposes the
CList data in a form that .NET can see --> aka a COM
SafeArray of COM objects, or a C style array of structs of
primtiive types...

3) Reject the VS 6.0 approach as too painful and instead
go the {almost as painful} route of a mixed model DLL; a
C++ DLL that contains both managed and unmanaged code. In
THEORY you can expose Managed C++ classes from the DLL
{that C# can use} and you can implement those classes such
that they properly initialize MFC and then manipulate the
CList.

--Richard
-----Original Message-----
I am importing a visual 6 C++ dll into C#. The methods in
the dll take a CList type and I was wondering what type in
C# can I use that correctly matches the CList type. Is the
ArrayList type in C# comparable or should I just create my
own List type in C#?
 
Back
Top