I am attempting to write a C# class (2010) that allows the usage of functions contained in a legacy C++开发者_开发百科 dll. The functions are exported using __stdcall, and have varying sets of parameters. I have no issue dealing with strings and other primatives, and am able to invoke these functions without issue.
The problem is that a few of the functions contain a CArray & reference as a parameter. I cannot figure out how to marshal this datatype, or if it's even possible.
I can't change the legacy DLL code, unfortunately.
To deal with this correctly, you can make a wrapper DLL (using the same MFC/C++ runtime version as what you want to call into, and make sure accepts the same array in the form of, say, a traditional pointer to a native C++ array.
This wrapper DLL can be called into from C#.
You could try with a more recent MFC version (and use C++/CLI for the marshalling), but then the new CArray
could be binary incompatible with what to legacy library expects.
精彩评论