- C# code
//API 原型int GetPeopleName(char *strTmp, int *strLen) //PB10.5中 我声明和调用的情况public function integer GetPeopleName(ref string strTmp,ref integer strLen) library "termb.dll" ls_name =''li_name = 30 GetPeopleName(ls_name,li_name)sle_name.text = ls_name//下面是C#里调用情况,测试通过[DllImport("termb.dll", EntryPoint = "GetPeopleName", CharSet = CharSet.Ansi, SetLastError = false)] public static extern unsafe int GetPeopleName(ref byte strTmp, ref int strLen);// 声明 byte[] name = new byte[30]; int length = 30; GetPeopleName(ref name[0], ref length);lblName.Text = System.Text.Encoding.GetEncoding("GB2312").GetString(name);//现在 我在PB里调用出现的情况是,sle_name.text 出现的是乱码,我不知道声明的数据类型对不对,还请各位指点
------解决方案--------------------
如果用PB10以上含PB10,申明外部函数时需要再申明后加上;ansi
------解决方案--------------------
怎么加的?肯定要加的!
------解决方案--------------------
试一下:
ls_name = space(30)
li_name = 30
GetPeopleName(ls_name,li_name)
sle_name.text = ls_name
或者:
char lc_name[]
li_name = 30
GetPeopleName(ls_name,li_name)
sle_name.text = ls_name