Hi. I've managed to get the C code I need into a dll, and my C# program can access some functions. There are other functions though, and I don't know how to access them from C# because they involve a struct declared in the C code. The example I have been working from is the following:
C-struct:
[PHP]struct STRUCT_DLL
{
int count_int;
int* ints;
};[/PHP]
C# code:
[PHP]class call_dll
{
[StructLayout(LayoutKind.Sequential, Pack = 1)]
private struct STRUCT_DLL
{
public Int32 count_int;
public IntPtr ints;
}
[DllImport("mingw.dll")]
private static extern int func_dll(int an_int, [MarshalAs(UnmanagedType.LPArray)] byte[] string_filled_in_dll, ref STRUCT_DLL s);
[DllImport("mingw.dll")]
private static extern int func2(int a, int b);
public static void Main()
{
...
}
}[/PHP]
That works fine. Now, if the C-struct is this:
[PHP]struct vector
{
uint elem_count; /* number of items in the vector */
uint size; /* size of the vector */
uint elem_size; /* element size */
int (*cmp)(const void *, const void *);
void *table;
};[/PHP]
I change my C# code to the following:
[PHP] [StructLayout(LayoutKind.Sequential, Pack = 1)]
unsafe private struct STRUCT_DLL
{
public uint elem_count;
public uint size;
public uint elem_size;
//int (*cmp)(const void *, const void *);
public void* table;
}[/PHP]
It compiles, but not when the commented line is...not commented. I have no idea how to proceed. I know you can put methods in structs in C#, but when it comes to function pointers, I am lost. Also, how would I DllImport a function from the C dll that is for example "vector *sdMake(int a, char b, ...)" ? I guess any function pointers give me problems.
I would appreciate any help.