c#调用c++的DLL,不能正确返回值,高手帮忙解决,急!!!!
有一个C++生成的dll,名称为test.dll,入口点为_datadown@12其中包含一个方法 string datadown_sp(string inputstring,string type,ref string outstring).其中,type值为固定的,TYPE="U".在C#中调用后,不能正常返回值.
正常运行的结果应该返回两个值,一个是datadown_sp.一个是outstring.但调用后,datadown_sp返回乱码,outstring返回初始定义的值.
代码如下:
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices; //使用C#导入dll必须的
namespace csharptest
{
class Program
{
// dll中导出函数的声明
[DllImport("test.dll", EntryPoint="_datadown@12",CallingConvention=CallingConvention.Winapi)]
public extern static string datadown_sp(string inputstring,string type,ref string outstring);
static void Mytest()
{
try
{
string returnstring;
string outstring="";
string savestring;
returnstring=datadown_sp(";123455=#","U",ref outstring);
savestring=outstring;
}
}
}
}
正常运行结果应该是:retrunstring="0|16",savestring="123455 #".但上面代码中returnstring返回是乱码,savestring的值返回是"".
高手们帮忙解决下,着急呀!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
[DllImport("CFDll.dll", EntryPoint = "CFISO15693_Inventory")]
public static extern int CFISO15693_Inventory(ushort wDevID, ref byte[] pData, ref byte pLength);
调用:
int cfIso15693_inventory;
byte[] dsfidUid = new byte[20];
ushort x = 0;
cfIso15693_inventory = CFISO15693_Inventory(x, ref dsfidUid, ref length);