各位高手赶快帮帮忙。
现在有一个delphi写的dll,函数中有PInteger的返回参数,在delphi中可以正常调用,但是我在vb里写的时候就不知道该怎么来调用了。请看代码
以下是delphi中的函数定义和调用代码,能正常运行定义
function  CommitCurrentPayCashCardList2(iBillID: Integer;  sCashier: PChar; piTransID: PInteger): Integer; stdcall;external 'CRMInterface.dll';
调用
  iXPH :integer;
  iTransID :integer;
  iXPH := strToint(edXPH.Text );   if CommitCurrentPayCashCardList2(iXPH,PChar(edSKY.Text),@iTransID)=1 then
   begin
     ShowMessage('消费成功');
   end下面是我在vb里写的定义和调用,但是一运行程序就崩溃,请大家快给支招吧,谢谢了。急死我了!
定义
Public Declare Function CommitCurrentPayCashCardList2 _
    Lib "CRMInterface.dll" _
    (ByVal iBillID As Integer, _
    ByVal sCashier As String, _
    ByVal iTransID As Long) As Long
调用
iXPH = 1
emplID = "1"If CommitCurrentPayCashCardList2(iXPH, emplID, VarPtr(iTransID)) = 1 Then
    MsgBox "success"
Else
    MsgBox "err"
End If

解决方案 »

  1.   

    冒是vb和delphi是仇人加对家。
      

  2.   

    VB调用dll,除了VB写的外,其它语言写的必须是标准的dll控件,这个做很麻烦一般人都不会花时间做这个的,你还是把这个dll转译成VB自己写个类模块最现实了。
      

  3.   

    dll是第三方提供的,要跟其他系统有接口的,所以dll不可能是我们自己开发。
      

  4.   

    看你说的这么要紧,我帮你google下。
    https://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=23628&lngWId=1
      

  5.   

    试试以下两种方法:
    1、引用库
    2、AVI声明
      

  6.   

    还是不行啊同志们。
    8楼给的例子太简单了,函数都没有参数,呵呵。现在我这里其他的函数都能跑通,唯独这个带pinteger类型参数的这个函数不行。这里的itransID是个返回参数。实在是不知道怎么调用。
      

  7.   

    试试declare function() as inteter?
      

  8.   

    Delphi 和VB的数据类型是否相同 ,VB调用全换成long看看吧
      

  9.   

    integer好象不行。
    又找了几个
    http://groups.google.co.uk/group/microsoft.public.vb.general.discussion/browse_thread/thread/cfbad3202f2e150e/20450ad3c0e08e7fhttp://stackoverflow.com/questions/295620/how-to-call-a-delphi-dll-from-vb6
    。net的
    http://topic.csdn.net/t/20050407/18/3918048.html
      

  10.   

    Thank you for the materials you offered, but these have no help to me.
    I've test all the cases writter in these matersials but all failed.
    I changed each 'integer' to 'long', and took other advised, but no success happend.
    Thank you all the same, and I am eager to some other solutions.
      

  11.   

    4字节整数在 VB 中是 Long 类型。
    不仅参数 iBillID  要声明成 Long,否则参数堆栈大小不对;
    而且变量 iTransID 也必须是 Long 类型,否则你只有2个字节的空间,对方却要用4个字节,当然会崩溃了。
    Public Declare Function CommitCurrentPayCashCardList2 _ 
        Lib "CRMInterface.dll" _ 
        (ByVal iBillID As Long, _ 
        ByVal sCashier As String, _ 
        ByRef iTransID As Long) As Long dim iXPH as long
    dim emplID as string
    dim iTransID as long iXPH = 1 
    emplID = "1" 'ByRef 参数会自动取地址,不需要 VarPtr 了'
    If CommitCurrentPayCashCardList2(iXPH, emplID, iTransID) = 1 Then 
        MsgBox "success" 
    Else 
        MsgBox "err" 
    End If 
      

  12.   

    回老鸟:
    依然崩溃。
    "该内存不能为read"
      

  13.   

    我搜索的时候看到有些帖子里有讲copymemory。
    楼主用 ‘delphi dll' copymemory vb google下。
      

  14.   

    他的dll在C++下是成功过的,所以我想能不能用c++写个dll来调delphi的dll,然后我用vb来调用c++的dll。相当于在delphi的dll外面包一层。可是不会写c++,有没有好心人帮帮忙啊。