c# char unsigned_unsigned char型**相当于C#和必须写在文件中的返回值

I have to call a win32 dll function

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

and i need wrapped in c# as

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

and i called it from a c# application as

int arg1;

IntPtr arg2 = IntPtr.Zero;

IntPtr arg3 = IntPtr.Zero;

func1(arg1,out arg2,out arg3);

Is the function declared in the c# wrapper as well as called in C# test app Correct ?

Now i need to store the arg2 in a text file. How to do that.

Got answer from Hans and i wrote it in a file using

System.IO.StreamWriter(@Application.StartupPath + "\\Filename.txt");

file.WriteLine(arg2);

file.Close();

解决方案i have a free function in the dll to clear the memory

Then you have a shot at making this work. The function declaration ought to look like this:

[DllImport("foo.dll", CallingConvention = CallingConvention.Cdecl)]

private static extern int func1(int arg1, out IntPtr arg2, ref int arg3);

And you'd call it like this:

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

Where "func1free" is the otherwise undocumented function that releases the string.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值