I have some ANSI standard C code which is authoritative. What that means is that although I have the source, I can not translate to another language nor modify calling arguments, as those actions would invalidate the authority. There are over 150 functions.
I can make incidental changes, such as change the file names from .C to .CPP so that it compiles using Visual Studio 2009's C++ compiler, which I have done. Compiler directives and such can also be added. I can also go through a wrapper layer, if necessary.
Another restriction is my company does not want me to use the unsafe key word in any C# code.
I need to get at these functions from a C# program.
A typical C/C++ function looks like this:
double SomeFunction(double a, double[3] vec, double[3][3] mat);
Where the array contents are sometimes input, sometimes output, and rarely both.
I first tried making an unmanaged DLL (with the functions marked Extern C). Functions with only simple arguments (int, double) worked fine, but I could not determine how to Marshal the arrays. (Actually, I did find some sample code, but it was extremely complex and unreasonable to duplicate 150 times.)
I then tried two projects within the same solution, one in C++ and the other in C#. In the C++ project, I created a managed function which just called the original function which was marked as unmanaged. This was extremely clean and simple, and again, simple arguments worked fine. But for arrays, I couldn't find how to make the argument types match across the C# to C++ boundary:
Argument '2': cannot convert from 'double[]' to 'double*'
(and as mentioned above, I can't use unsafe to get a pointer).
Certainly what I am trying to do must be possible.
What is the best way to get at these functions?
(Sample code using the above function would be really cool.)