C#编组的char **和unsigned char型** [英] C# Marshalling char** and unsigned char**

查看:1554
本文介绍了C#编组的char **和unsigned char型**的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里的问题是 - 我有我需要从C#应用程序中使用一些C图像处理库。 ,缺乏具有的DllImport经验令我很难现在

Here is the problem - i have some C image processing library that i need to use from C# application. Lack of experience with DllImport strikes me hard for now.

我需要使用看起来像功能:

The function i need to use looks like:


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



所以,它接受原始图像数据,包含XML参数和图像width'height,然后返回处理后的图像以及一些XML报告

So, it accepts raw image data, xml containing parameters and image width'height and then return processed image and some xml report.

现在我试着去接近它是这样的:

For now im trying to approach it like this:


 [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);



但没有任何成功。

but without any success.

任何建议,应该怎样做呢?

Any suggestions how should it be done?

编辑:
仍然没有运气((
。通过杂乱的C ++ CLI做到了现在。

still no luck (( done it by messy C++ CLI for now

推荐答案

有关输出参数,你应该使用访问的 Marshal.PtrToStringAnsi

For the output parameters, you should access the returned data using Marshal.PtrToStringAnsi.

由于原来的记忆被非托管API中分配的,它仍然是你的责任,以释放它为宜。

Since the original memory was allocated within the unmanaged API, it's still your responsibility to free it as appropriate.

我也觉得,为什么第一个是你应该使用字符串双方的前两个参数,不知道一个的IntPtr

I also think that you should use String on both the first two parameters, not sure why the first one is an IntPtr?

这篇关于C#编组的char **和unsigned char型**的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆