淡定从容,宁静致远
全部博文(329)
分类: C#/.net
2014-11-10 14:08:12
extern "C" __declspec(dllexport) int scanRe(char* data)
{
strcpy(data,"47");
return 0;
}
在c#中接收返回值用 ref byte
[DllImport("PDAScandll.dll",CharSet=System.Runtime.InteropServices.CharSet.Auto)]
public static extern int scanRe( ref byte param2);
private void button1_Click(object sender, EventArgs e)
{
byte[] param2 = new byte[255];//新建字节数组
scanRe(ref param2[0]);//向dll函数传入参数
string s = System.Text.Encoding.GetEncoding("GB2312").GetString(param2, 0, param2.Length);
//将字节数组转换为字符串
label1.Text =s;
}