c#中的unsigned char **等价物,必须在文件中写入返回值

我必须调用win32 dll函数

int func1( int arg1, unsigned char **arg2, int *arg3); 

我需要用c#包装

 public extern int fuc1(int arg1, out IntPtr arg2, out IntPtr arg3); 

我从ac#application调用它

 int arg1; IntPtr arg2 = IntPtr.Zero; IntPtr arg3 = IntPtr.Zero; func1(arg1,out arg2,out arg3); 

函数是在c#包装器中声明的,也是在C#test app中调用的吗? 现在我需要将arg2存储在文本文件中。 怎么做。

得到了汉斯的回答,我用文件写了一个文件

 System.IO.StreamWriter(@Application.StartupPath + "\\Filename.txt"); file.WriteLine(arg2); file.Close(); 

我在dll中有一个自由函数来清除内存

然后你有机会完成这项工作。 函数声明应该如下所示:

 [DllImport("foo.dll", CallingConvention = CallingConvention.Cdecl)] private static extern int func1(int arg1, out IntPtr arg2, ref int arg3); 

你会这样称呼它:

 IntPtr ptr = IntPtr.Zero; int dunno = 99; string result = null; int retval = func1(42, out ptr, ref dunno); if (retval == success) { result = Marshal.PtrToStringAnsi(ptr); // etc... } if (ptr != IntPtr.Zero) func1free(ptr); 

其中“func1free”是释放字符串的其他未记录的函数。

您可能需要使用MarshalAs属性,例如:

 public static extern int func1(int arg1, [MarshalAs(UnmanagedType.LPStr)] string arg2, IntPtr arg3); 

点击此处查看文档:

http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.marshalasattribute.aspx