C
cees
Hi,
I need to call an external C-function that accept an array of void
pointers (void **). Each item can either be a single float,int,char or
a C-array of these types. Is that possible and if so how to do it most
elegantly?
I found a lot of samples and stuff in MSDN that got me some ideas but
somehow I am not able to progress to the exact situation I need, while
it seems simple.
Below you find a C#-sample, with in comment the working Ansi-C version
of the functionality I need.
Thanks in advance,
Cees
using System.Runtime.InteropServices; // DllImport
public class Sample {
[DllImport("containingFoo.dll")]
unsafe public static extern void foo(void **data);
/* C code sample
void callFromC()
{
extern void foo(void **data);
float f[4] = {1,2,3,4};
int i = 5;
void* data[2] = { &f, &i};
foo(data);
}
*/
unsafe static void callFromCSharp() {
float[] f = {1,2,3,4};
int i = 5;
void** data;
// in C: void* data[2] = { &f, &i};
// WHAT TO DO IN C#?
foo(data);
}
};
I need to call an external C-function that accept an array of void
pointers (void **). Each item can either be a single float,int,char or
a C-array of these types. Is that possible and if so how to do it most
elegantly?
I found a lot of samples and stuff in MSDN that got me some ideas but
somehow I am not able to progress to the exact situation I need, while
it seems simple.
Below you find a C#-sample, with in comment the working Ansi-C version
of the functionality I need.
Thanks in advance,
Cees
using System.Runtime.InteropServices; // DllImport
public class Sample {
[DllImport("containingFoo.dll")]
unsafe public static extern void foo(void **data);
/* C code sample
void callFromC()
{
extern void foo(void **data);
float f[4] = {1,2,3,4};
int i = 5;
void* data[2] = { &f, &i};
foo(data);
}
*/
unsafe static void callFromCSharp() {
float[] f = {1,2,3,4};
int i = 5;
void** data;
// in C: void* data[2] = { &f, &i};
// WHAT TO DO IN C#?
foo(data);
}
};