将c#数组编组到静态c库的指针

将c#数组编组到静态c库的指针,c#,pointers,marshalling,static-libraries,zlib,C#,Pointers,Marshalling,Static Libraries,Zlib,我仍然在努力从c静态库中调用一些函数。 在这之后,我用visualstudio围绕静态库编写了一个包装器,现在可以在c#端访问这些函数,但在处理它们时会出现一些错误 下面是函数的原始外观: ZEXTERN Int32 ZEXPORT compressZIP OF((unsigned char *dest, Uint32 destLen, unsigned char *source, Uint32 sourceLen,

我仍然在努力从c静态库中调用一些函数。 在这之后,我用visualstudio围绕静态库编写了一个包装器,现在可以在c#端访问这些函数,但在处理它们时会出现一些错误

下面是函数的原始外观:

ZEXTERN Int32 ZEXPORT compressZIP OF((unsigned char *dest,   Uint32 destLen,
                             unsigned char *source, Uint32 sourceLen,
                             Uint32 *_crc32));
这导致了从c#一侧到

所以,现在我陷入了指针问题,我尝试了一些东西,比如

byte[] data = new byte[size]
(fixed ptr = data)
并将PTR传递到函数中。但我总是会遇到一些内存冲突或其他内存异常

当我调用解压压缩包时,它看起来有点像,我得到了两个正确的解压字符,但只有围栏的东西


有人能帮我为函数填充正确的参数吗?

不要将其声明为C#端的指针,而是作为字节数组。并且一定要包括

一个有效的例子:

[DllImport("PixelFlowIE.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "PixelFlow")]
private static extern void PixelFlowDLL([In, Out] Node[] gi, int width, int height, SourceInfo[] sources, int sourceCount, int iterations, int iterPerPeriod, ProgressCallback prg);

但不管怎样,问题似乎在c方面
[DllImport("PixelFlowIE.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "PixelFlow")]
private static extern void PixelFlowDLL([In, Out] Node[] gi, int width, int height, SourceInfo[] sources, int sourceCount, int iterations, int iterPerPeriod, ProgressCallback prg);