I am creating a .NET adapter for the following C API:
void GetStringList(const char *** listOut, rsize_t * listCountOut);
I want a C# adapter that looks like:
[DllImport("api.dll", CallingConvention = CallingConvention.Cdecl)]
static extern
void GetStringList(
out string[] listOut,
out int listCountOut
);
This doesn't work because the marshaller does not know the out list length is provided by the second parameter. Also, I can't set up an IntPtr, because the length is not known until the function returns.
I can solve this with unsafe.
Is there a better way without unsafe?
I found a way without unsafe. It is to use IntPtr for the list, followed by drilling down to get list item IntPtrs.
and then something like
Good enough for my purposes.