pb 调用dll 用delphi 怎么写?

luobo180180 2017-08-29 03:44:41
PB代码如下:
type prototypes
function string YBTS(string pRcv) library "ybpost.dll" library "ybpost.dll" ALIAS FOR "YBTS;ansi"
function string SendRcvA(ref string pSend, ref string pRcv) library "SendRcvA.dll" ALIAS FOR "SendRcv;ansi"
function int SIReadCardIDAIO( ref string sCardNo, ref string sCardId,ref string sInitOrgNo) library "SI_ICCReader.DLL" ALIAS FOR "SIReadCardIDAIO;ansi"
end prototypes
..........
forward prototypes
public function integer uf_sendrcva (string as_messagecode, string as_message, string as_knxx)
end prototypes

public function integer uf_sendrcva (string as_messagecode, string as_message, string as_knxx);
//==============================================================================
// 函数: nvo_ybjk::uf_sendrcv()
//------------------------------------------------------------------------------
// 参数:
// value string as_send
//------------------------------------------------------------------------------
// 返回值: integer
//------------------------------------------------------------------------------
//==============================================================================

String ls_return
String ls_fetch
String ls_inparm, ls_outparm

ls_inparm = as_knxx
ls_outparm = space(4096)

if ib_debug then

openwithparm(w_wzyb_sendparm, ls_inparm)

ls_outparm = message.stringparm
if ls_outparm = '' then return -1
else
try
// messagebox("",ls_inparm)
uf_log(ls_inparm,ls_outparm)
ls_return = SendRcvA(ref ls_inparm,ref ls_outparm)

catch(runtimeerror err)
is_error_text = "调用SendRcvA出错(" + as_messagecode + "):" + err.GetMessage()
return -1
end try

end if

Return 0
end function
..............
PB代码结束

我想用delphi写出同样的调用方法,由于刚入门,请大神写详细些,谢谢! 收起
下面是我写的
function SendRcvA(pSend, pRcv: PAnsiChar):string; stdcall; external 'SendRcvA.dll' name 'SendRcv';
.......

function uf_sendrcva(as_messagecode, as_message, as_knxx: String):String;
begin

pRcv := as_knxx;
pSend := as_knxx;
ls_return := SendRcvA(PAnsiChar(pSend),PAnsiChar(pRcv));
//调用
memo2.Text := uf_sendrcva('G002', memo2.Text, memo2.Text);
测试没有任何信息发送和返回
...全文
1589 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
luobo180180 2017-09-16
  • 打赏
  • 举报
回复
引用 1 楼 mrwyf 的回复:
pb中的string对用delphi中用pchar类型,需要stralloc分配空间(对应pb的space)和strdispose释放空间。 SendRcvA(PAnsiChar(pSend),PAnsiChar(pRcv)); 对于pRcv之类用来接收返回的数据,你要申请变量 pchar类型,用stralloc分配后传入,你PAnsiChar(pRcv)强制转换传入,肯定不行
谢谢!,我已经自己解决了,分照给,感谢
流星飞520 2017-08-30
  • 打赏
  • 举报
回复
很久没写delphi了,我就文本打字给你写个例子吧,你试着调试下: function uf_sendrcva(as_messagecode, as_message, as_knxx: String): String; var pRcv, p_return: PAnsiChar; begin pRcv := stralloc(4096); p_return = stralloc(4096); try StrPCopy(pRcv, as_knxx); StrCopy(p_return, SendRcvA(PAnsiChar(as_knxx), pRcv)); //uf_sendrcva 你自己对应着改 //memo2.Text := uf_sendrcva('G002', memo2.Text, memo2.Text); finally StrDispose(rRcv); StrDispose(p_return); end; end;
流星飞520 2017-08-30
  • 打赏
  • 举报
回复
pb中的string对用delphi中用pchar类型,需要stralloc分配空间(对应pb的space)和strdispose释放空间。 SendRcvA(PAnsiChar(pSend),PAnsiChar(pRcv)); 对于pRcv之类用来接收返回的数据,你要申请变量 pchar类型,用stralloc分配后传入,你PAnsiChar(pRcv)强制转换传入,肯定不行

5,402

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧