首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

C#调用c++dll参数有关问题

2012-09-27 
C#调用c++dll参数问题函数原型如下:public virtual int Base64Decode(ref short @in, ref short @out, sho

C#调用c++dll参数问题
函数原型如下:
public virtual int Base64Decode(ref short @in, ref short @out, short len);

要在c#中调用 in传进去的应该是byte[]或者string,
out传出的也应该是byte[]或者string
但是short @in我真的不知道什么意思,应该怎样传参数,第一次接触c# 求教

[解决办法]
用int16[]试试
[解决办法]
@是转义,无视即可。
不过LZ你这
public virtual int Base64Decode(ref short @in, ref short @out, short len);
是C#吧,和C++有什么关系?
[解决办法]
首先:
// long Base64Decode(short * in, short * out, short len);
[DllImport("xxxx.dll", CallingConvention = CallingConvention.StdCall)]
public static extern long Base64Decode(IntPtr in, IntPtr out, short len);
// 把 API 定义成 C# 识别的接口

其次:
在使用原 C++ short* in 的 in变量自己需要定义一个 short[] _in 变量, 并new 出len 那么多
例如 short[] _in = new short[32];
准备好里面的数据
然后
IntPtr in_todll = GCHandle.ToIntPtr(_in);
同理,out 也一样
传进去即可
注意取 out 时用 Marshal.PtrToStructure() 前面强转成 C# 定义好的 out 类型。

热点排行