I have a C function that takes several arguments of double indirected pointers.
something like this
int myFunction (int ** foo, int** bar, int **baz){
int size = figureOutSizeFunction();
*foo = (int*) malloc (sizeof(int) * size);
return SomeOtherValue;
}
Now in C# I am trying to pass it a ref to an IntPtr, however the IntPtr is always zero. And when I pass those values to the next DLL C function the DLL fails with a System Access Violation. I know that the code works in a C only environment (I have a “main” that tests the code) however, it is not working when called from C#
What variable type do I need in C# to pass to the C DLL? ref ref int?
When dealing with double pointers (
**) the best way is to just marshal them asIntPtr.The digging into the double pointer is then done in managed code.
The above code is obviously a bit … ugly. I prefer to wrap it in nice extension methods on
IntPtr.Then the above can be rewritten as the more readable