By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,670 Members | 1,512 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,670 IT Pros & Developers. It's quick & easy.

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

P: n/a
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#?
Nov 15 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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#?.

Nov 15 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.