I have the following struct in a C DLL:
struct foo
{
double *x;
short *y;
}
The c# app that calls the DLL:
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public class foo
{
public ? x;
public ? y;
}
I understand that I should use IntPtr if I have an int*, but can’t find equivalent for short* and double *.
On the C side, I am using the short * to allocate an array of shorts, the double * for array of doubles.
Actually, all unmanaged pointers in C# are represented using
IntPtr. It’s calledIntPtrnot because it’s an analogue toint *, but rather because it is an integer of “pointer” size (in contrast toInt32andInt64, which are integers of 32- and 64-bits respectively). Its size is platform dependent.To get the value of
x[0], for example, you’d doTo read
*y, you’d do