I have a dll written in C that gets imported into a C# application. All I need from the dll is read out a few values from a hardware device, the actual read process is done by a function in the C dll. Now I want to read out all the values with this single function and return them to C# in an fast and easy way. It is a very "general" multi plattform C library that consists of a few functions to handle the communication with said hardware device. I'm looking for a general "C to C#" answer that doesn't have to be specific for my case.
I'm not very experienced in C and C# which makes the task rather complicated (I have no choice about the language). What would be a smart way to do this in C and how do I declare it in C and how I do import it properly in C#?
Here some Pseudo code to make my question a bit clearer. Thats not valid code but should make clear what I'm after C:
int [] read(){
int results [3];
results[0] = getPosition();
results[1] = getOrientation();
results[2] = getTouch();
return results;
}
C#
[DllImport("myDll.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern int[] read();
int [] cReturn = new int[3];
cReturn = read();
I tried returning an int array and marshal it in C#, as all my values are int types but it seems returning arrays isn't something you would do in C.
I found quite a few examples for C++ but none of them worked with C as they used C++ specific functions.