C# - How To Marshal Int Arrays
I'm working with C# an I have a third party dll that needs int arrays as
parameters. How do I marshal an int array between C# and C/C++ ? The
functions are declared like this:
__declspec(dllimport) void __stdcall ReadStuff(int id, int* buffer);
In C int* would be a pointer right ? So I'm confused if I have to use
IntPtr or if I could use int[] (preferred) ? I thought this might be ok:
[DllImport(dllName)]
static extern void ReadStuff(int id, [MarshalAs(UnmanagedType.SafeArray,
SafeArraySubType = VarEnum.VT_I4)] int[] buffer);
Would that work ? Or how do I have to declare this function in C# in safe
code ?
No comments:
Post a Comment