We hired a C programmer to develop a native component for use in a .NET application. We agreed on a conceptual API. I will pass his method two arrays and he will give back an array. I got the code today. Here is the header file. Real names are obscured:
__declspec(dllexport) int NativeMethod(
struct params * config,
int c_input_a_rows,
struct input_a_row *input_a_rows,
int c_input_b_rows,
struct input_b_row *input_b_rows,
int c_count,
int *p_c_output_rows,
struct output_row * output_rows);
struct params
{
int a;
int b;
int c;
double d;
double e;
int f;
int g;
char h[1000];
};
struct input_a_row
{
int a;
int b;
double c;
};
struct input_b_row
{
int a;
int b;
int c;
int d;
int e;
double f;
double g;
};
struct output_row
{
int a;
int b;
int c;
int d;
int e;
int f;
int g;
double h;
double i;
double j;
};
From this I generated .NET code using P/Invoke Interop Assistant. I was not able to get it to work by opening the DLL. It complained that the file has no assembly manifest. So I plugged the header file into the SigImpl Translate Snipped and got this:
[DllImport("the.dll", EntryPoint="NativeMethod")]
public static extern int NativeMethod(
ref params config,
int c_input_a_rows,
ref input_a_row input_a_rows,
int c_input_b_rows,
ref input_b_row input_b_rows,
int c_count,
ref int p_c_output_rows,
ref output_row output_rows);
It also create all as structs as expected. Each one has a class attribute:
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
Two questions. Did this code generate correctly? Second, how do I use it? The signature does not have arrays. I know I probably need to use pointers somehow, but how? I don’t expect you to solve this for me, but can you point me to some way to understand how to figure it out without taking a course in low native programming? Thanks!
Okay, after I posted this question I started hacking away again. The first thing I tried worked!
There’s one other thing I had to do. I was getting an error that entry point was not found. I solved this by using DUMPBIN (from VS console) to find out that the export was actually named
?NativeMethod@@YAHPAUconfig@@HPAUinput_row_a@@HPAUinput_row_b@@HPAHPAUoutput_row@@@Z. How fragile is that?!