I currently have a C function that I’d like to use in .NET (C#).
I can see two ways of achieving this:
-
Compiling it (I think this is possible) with /clr on VC++.NET, having implemented “façade” managed methods that call the C code.
-
Compiling the C code as a DLL and then making API calls.
What do you find best? How to do the first of them?
Update
As requested, here is the (only) function I need to call from my managed code:
int new_game(double* params1, double* params2);
Just one more question (though harder)
I have one function of the form
int my_hard_to_interop_function(double** input, double **output, int width);
where input and output are both 2D double arrays. Their width is given by width and their height is known by the function. I am supposed to call this C method from my C# application.
If this is a simple C API then the most straight forward way to access it is using PInvoke. PInvoke was designed for exactly this scenario.
Could you post the signature of the C methods? If so we could provide the appropriate managed signatures.
EDIT
As Hans pointed out given the plural name of the parameters it seems possible these are arrays vs. single values. If so then the signature would need to change to account for that. For example if they are expected to be a predetermined fixed size the signature would look like the following