The obvious mistake in your translation is in the third member of bufferstrm
struct implstrm* some_struct;
This is a pointer to a struct. Based on the name, this struct, provides the actual implementation of the stream. The bufferstrm
struct wraps that raw stream with a buffering layer. At least, that's what the names suggest.
Now in the C# code, you translated some_struct
as an in-line struct, rather than a pointer. That is obviously wrong. It should be:
public struct bufferstrm
{
public BUFSTRM_bytes_usage bytes_usage;
public BUFSTRM_get_stuff get_stuff;
public IntPtr some_struct;
}
You'll need to use Marshal.StructureToPtr
to create this pointer.
Beyond that, it seems quite plausible that the two functions that you provide are implemented incorrectly. You've given any details of that the functions are expected to do. Perhaps get_stuff
is not allowed to return a null pointer. There's no way for us to check any of that because you've only given the prototype of the functions, but omitted details of the semantic rules that the functions must obey.
So I suspect that the delegates you pass are incorrect. But only somebody with knowledge of what they are expected to do can understand how to correct them.