I have a function like this :
extern "C" __declspec(dllexport) void Step(int * oSamplesCount, float * oSamples){
// (approximative syntax for clarity)
*oSamplesCount = new_samples_count (some number between 0 and 16000)
oSamples[ 0 .. new_samples_count ] = some floats (sound data)
}
I'd like to call it from C# :
float [] mSamples = new float[16000];
[DllImport("Lib.dll")]
static extern void Step(ref Int32 oSamplesCount, [MarshalAs(UnmanagedType.LPArray,SizeConst=16000)] ref float [] oSamples);
void update(){
Int32 lSamplesCount = 0;
Step(ref lSamplesCount, ref mSamples);
}
The C function is called correctly, the for() loop that fills the samples array is ok, but it crashes somewhere between the return and the next C# line, so I guess it has something to do with unmarshalling, although I don't want any marshalling/unmarshalling (the array is blittable and must be written to from C)
I can't use /unsafe. I tried SizeConst and various other permutations.
Any help is appreciated !