PB调用DELPHI的DLL之间传值的问题,大家来看看

PB调用DELPHI的DLL之间传值的问题,大家来看看 Delphi / Windows SDK/API
http://www.delphi2007.net/DelphiAPI/html/delphi_20061110115522258.html
 
  PB的主程序调用DELPHI的DLL,DLL在函数执行完后回传一个字符串给PB主程序,DLL里用的是PCHAR类型。。PB下该怎么接收?        
   
   
  int   RC,SectorID=15,i=1  
  char   ReadStr[64]  
  int   li_data[64]  
  char   ls_data[64]  
  string   data=''  
   
  Rc   =   M1QueryCard(15,ref   ReadStr)  
   
  do   while   i<=64  
  li_data[i]=asc(ReadStr[i])  
  ls_data[i]=get_hex(li_data[i])  
  i++  
  loop  
   
  //ReadStr=get_hex_str(ReadStr)  
  messagebox('FOXHIS',ls_data)      
   
  以上是PB的程序。。。 M1QueryCard(15,ref   ReadStr) 这个是我DELPHI写的DLL里的函数。。ReadStr 是DLL以PCHAR类型回传的一个字符串    
   
  现在这样不能用,读不到数据。。哪位知道是什么问题么

把你的delphi的dll函数类型,及相关代码也贴一下,否则怎么看得出来呢?  
   
 

DELPHI的DLL代码:  
   
  var  
      ReadCardDataHex:   string;  //全局变量  
   
  Function   M1QueryCard(SectorID:Shortint;var   CardDatas:PChar):integer;   stdcall;     //查询卡  
  var  
  ....  
  HexData1,HexData2:   string;  
  begin  
          .....  
          for   i:=0   to   15   do  
          begin  
              HexData2:=   HexData2+IntToHex(CardData2[i],2);  
          end;  
      end;  
      ReadCardDataHex   :=   HexData1+HexData2;  
      CardDatas:=Pchar(ReadCardDataHex);  
      result:=0;  
  end;  
   
   
   
  我DELPHI程序这样调用正常:  
  Function   M1QueryCard(SectorID:Shortint;var   CardDatas:PChar):integer;stdcall;external   M1Dll;  
 

pb调用delphi中dll,这种不同开发工具之间调试问题;  
   
  可以这样做,用delphi写一个小小的测试程序,用于测试dll,确保dll功能正确后,再由PB调用测试;  
   
  注意PB中的External   Functions中,定义的dll输出类型要正确,一般来说,应该没有什么太大的问题的。

哦,这么快就贴出来了,  
   
  我觉得问题在这里:  
   
  CardDatas:=Pchar(ReadCardDataHex);//ReadCardDataHex是一个String类,这仅仅是指针指向而已,  
   
  改成这样试试:  
  StrCopy(CardDatas,ReadCardDataHex);

StrCopy(CardDatas,pchar(ReadCardDataHex));  
   
  要这样才能编译。。这样也不行,程序死掉了。DLL里的代码还没执行完就提示 XX错误,问要不要发送了。。

你的M1QueryCard在PB中是怎么声明的呀?

Function   int   M1QueryCard(int   SectorID,ref   string   CardDatas)   library     'm1.dll';  
   
  以前是这样定义的,不能用。不知道对方现在有没改动过

我不记得PB中的string是什么特别的类型了,改为  
   
  在delphi中Pchar,就是cha指针,而你上面的PB代码:char   ReadStr[64];  
   
  定义改为这样试试:  
  Function   int   M1QueryCard(int   SectorID,ref   char*   CardDatas)   library   'm1.dll';  
   
  呵呵,我也不确定是否行,有几年没有用PB了,忘记了

另外,你的delphi测试代码是怎么调用的呢?  
   
  如果dll的第二个参数不用var,会怎么样,这样试试:  
   
  Function   M1QueryCard(SectorID:Shortint;CardDatas:PChar):integer;   stdcall;   //查询卡  
  ...

不用VAR会得不到回传的值。  
  DELPHI调用时声明为:  
  Function   M1QueryCard(SectorID:Shortint;var   CardDatas:PChar):integer;stdcall;external   'm1.dll';  
   
  唉。郁闷。。现在搞不定。。用简单的方法用着。。我把读出的数据保存为文本文件,对方打开文件读进来处理。。

这样定义:  
  Function   M1QueryCard(SectorID:Shortint;CardDatas:PChar):integer;   stdcall;  
   
  delphi中,pchar类型,不用var也是可以返回数据的,  
   
  var  
      cc:Array   [0..256]   of   char  
      ii:shortint;  
  begin  
       
      M1QueryCard(i,cc);  
       
      showmessage(cc);//这样是可以返回数据的吧    
   
   
   
   
   
 

这样试试:  
   
  delphi的dll中:    
  Function   M1QueryCard(SectorID:Shortint;CardDatas:PChar):integer;   stdcall;  
   
  PB声明:  
  Function   int   M1QueryCard(int   SectorID,ref   string   CardDatas)   library   'm1.dll';  
   
  如果这样都不行,呵呵,也想不什么问题了,我的机子上的PB早就删除了

噢。郁闷。。这样没试过。我的DELPHI程序调用是没问题的。现在就是PB有问题。。  
  下午跟对方说好了。。我保存成文件,他来读。。现在靠这样传数据。。汗。。真郁闷

PB程序可以这样写:  
   
  int   RC,SectorID=15,i=1  
  string   ReadStr  
  int   li_data[64]  
  char   ls_data[64]  
  string   data=''  
   
  readstr   =   spaces(64)  
  Rc   =   M1QueryCard(15,ReadStr)  
   
  PB声明:  
  function   M1QueryCard(integer   len,ref   string   ReadStr)   ......  
   
   
  Delphi程序这样写试试:  
  Function   M1QueryCard(SectorID:integer;CardDatas:PChar):integer;   stdcall;  
 

shortint PB不支持。

用   FastMM

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值