I have a .NET managed C++ application that needs to call a 3rd party
dll that was built with VC6 and returns MFC types. e.g.
int GetSomeStrings(CStringArray *pStringArray);
The problem I'm having is the destructor of the CStringArray is
crashing. Is it possible to call VC6 dlls that use MFC from .NET?
Seeing as no answered yet I'll take a shot.
your dll is built against MFC42.
VS2005 ships with MFC80.
The first problem is that the types don't match, which can be a problem
especially in constructors and destructors since that is where most
allocation/deallocation is done.
Maybe you could try (don't know if it will work or not) to point your
include and lib directories for that project to the VC6 folders. However that
would still mean they use a different CRT runtime version.
And that is the second problem.
assuming you would get it to work, the limitation is that none of the 2
components should allocate or deallocate memory of an object that was created
in the other component.
If your dll adds elements to an array, which is then deleted by your VC2005
program, your program crashes because it will try to delete memory that it
does not own. The same goes for modifying string data etc. anything in your
dll that allocates or deallocates memory in an object that was created by
your app.
The best option would be to recompile the dll in VS2005, if possible.
This is the general problem with dlls. in order to keep them portable across
multiple compiler versions you have to restrict it to only use C style
functions, and always keep memory ownership inside the component where it was
allocated.
--
Kind regards,
Bruno.
(e-mail address removed)
Remove only "_nos_pam"