各位高手赶快帮帮忙。
现在有一个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
现在有一个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
https://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=23628&lngWId=1
1、引用库
2、AVI声明
8楼给的例子太简单了,函数都没有参数,呵呵。现在我这里其他的函数都能跑通,唯独这个带pinteger类型参数的这个函数不行。这里的itransID是个返回参数。实在是不知道怎么调用。
又找了几个
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
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.
不仅参数 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
依然崩溃。
"该内存不能为read"
楼主用 ‘delphi dll' copymemory vb google下。