C#编组char **和unsigned char **

这是问题 – 我需要在C#应用程序中使用一些C图像处理库。 DllImport缺乏经验让我很难受。

我需要使用的function如下:

IMAGEPROCESS_API const int importImage ( const unsigned char* image, const char* xmlInput, unsigned char** resultImage, char** xmlOutput ); 

因此,它接受原始图像数据,xml包含参数和图像宽度’高度,然后返回处理后的图像和一些xml报告。

现在我试图像这样接近它:

  [DllImport(“imageprocess.dll”,CallingConvention = CallingConvention.StdCall,EntryPoint =“importImage”,CharSet = CharSet.Ansi)]
         private static extern int ImportImageNative(IntPtr imageData,String xmlDescriptor,out IntPtr processedImage,out IntPtr xmlOut);

但没有任何成功。

有什么建议应该怎么办?

编辑:仍然没有运气((现在由凌乱的C ++ CLI完成)

对于输出参数,您应该使用Marshal.PtrToStringAnsi访问返回的数据。

由于原始内存是在非托管API中分配的,因此您仍有责任在适当的时候释放它。

我还认为你应该在前两个参数上使用String ,不确定为什么第一个是IntPtr

试试这个

  [DllImport("imageprocess.dll", CharSet = CharSet.Auto, SetLastError = true)] static extern int importImage(string imageData, string xmlDescriptor, out string processedImage, out string xmlOut);