读书人

DLL调用很奇怪的有关问题求教

发布时间: 2013-11-29 13:49:33 作者: rapoo

DLL调用很奇怪的问题,求教!
我一个项目中有读食堂用的售饭机,DELPHI中调用成功,而PowerBuilder 9.0中调用不成功,求教。情况如下:

delphi中申明如下:
function SetConnectInfo(IConnectType:Integer;InPort:Integer; ITcpAddress:string;InBaud:Integer):Boolean; stdcall;far external DllName name '_SetConnectInfo@16';
function GetName(nDevice:Byte;Name:PChar;Version:PChar):Boolean; stdcall;far external DllName name '_GetName@12';
delphi中调用如下:
Name,Version:PChar;
SetConnectInfo(0,3,'',38400);
GetName(StrToInt(edt25.Text),Name,Version);
调用成功
我在PB中申明如下:
Public Function boolean SetConnectInfo(int IConnectType,int InPort,string ITcpAddress,int InBaud) LIBRARY "ICXF.dll" ALIAS FOR "_SetConnectInfo@16"
Public Function boolean GetName(char nDevice,ref char Name[],ref char Version[]) LIBRARY "ICXF.dll" ALIAS FOR "_GetName@12"
GetName函数中的nDevice分别试了int、char,Name、Version分别试了 ref char[]、ref string都不行。
SetConnectInfo调用成功
GetName 的调用试了好多种方式都失败



SetConnectInfo(0,3,'',38400) 成功

char name[],Version[]
for i=1 to 30
name[i]=char(0)
version[i]=char(0)
next
//机号:1
aa='1'
if GetName('1',Name[],Version[]) then
messagebox("",Name)
else
messagebox("系统提示","GetRecord失败!")
end if



string name,Version
name=space(30)
version=space(30)
aa='1'
if GetName(1,Name,Version) then
messagebox("",Name)
else
messagebox("系统提示","GetRecord失败!")
end if
[解决办法]
Public Function boolean GetName(char nDevice,ref char Name[],ref char Version[]) LIBRARY "ICXF.dll" ALIAS FOR "_GetName@12"

你说这里出错我就说这里吧!

如果是输出参数就是 ref string Name, ref string Version 就可以了。

调用是需要多少空间,看dll文档说明, PB分配空间就是 String Name = space(30)

我一直这么用,现在写的webService 接口也这么用没有任何问题!



[解决办法]
还有把错误提示贴出来! 也许错误就在你的动态库里面发生的!
[解决办法]
动态库不是你编写的吗?? 是就自己调式一下! 不是就找开发商给说法!
[解决办法]
设备厂商说不是他们的问题,说DELPHI能调用。晕啊

这不能说明PB能调用!

是我写的动态库一般会给出别的语言的调用样例!

读书人网 >.NET

热点推荐