100分!关于vb调用delphi编写的dll的问题,急!!!

liangzhifa 2009-11-19 05:55:04
各位高手赶快帮帮忙。
现在有一个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

...全文
183 20 打赏 收藏 转发到动态 举报
写回复
用AI写文章
20 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
我搜索的时候看到有些帖子里有讲copymemory。
楼主用 ‘delphi dll' copymemory vb google下。
liangzhifa 2009-11-20
  • 打赏
  • 举报
回复
会不会是内存释放的问题啊
liangzhifa 2009-11-20
  • 打赏
  • 举报
回复
回老鸟:
依然崩溃。
"该内存不能为read"
Tiger_Zhao 2009-11-20
  • 打赏
  • 举报
回复
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
liangzhifa 2009-11-20
  • 打赏
  • 举报
回复
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.

[Quote=引用 13 楼 patrickkong 的回复:]
integer好象不行。
又找了几个
http://groups.google.co.uk/group/microsoft.public.vb.general.discussion/browse_thread/thread/cfbad3202f2e150e/20450ad3c0e08e7f

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

http://stackoverflow.com/questions/295620/how-to-call-a-delphi-dll-from-vb6
。net的
http://topic.csdn.net/t/20050407/18/3918048.html
king06 2009-11-20
  • 打赏
  • 举报
回复
Delphi 和VB的数据类型是否相同 ,VB调用全换成long看看吧
  • 打赏
  • 举报
回复
试试declare function(。。。) as inteter?
liangzhifa 2009-11-20
  • 打赏
  • 举报
回复
还是不行啊同志们。
8楼给的例子太简单了,函数都没有参数,呵呵。

现在我这里其他的函数都能跑通,唯独这个带pinteger类型参数的这个函数不行。

这里的itransID是个返回参数。实在是不知道怎么调用。
cBirdNO1NO1 2009-11-20
  • 打赏
  • 举报
回复
试试以下两种方法:
1、引用库
2、AVI声明
  • 打赏
  • 举报
回复
看你说的这么要紧,我帮你google下。
https://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=23628&lngWId=1
liangzhifa 2009-11-20
  • 打赏
  • 举报
回复
他的dll在C++下是成功过的,所以我想能不能用c++写个dll来调delphi的dll,然后我用vb来调用c++的dll。相当于在delphi的dll外面包一层。

可是不会写c++,有没有好心人帮帮忙啊。
liangzhifa 2009-11-19
  • 打赏
  • 举报
回复
大家快点帮帮忙啊。明天再搞不定我就要倒霉了,555555
贝隆 2009-11-19
  • 打赏
  • 举报
回复
  • 打赏
  • 举报
回复
你看看没猩猩来,就是困难或无解。
100分嗷,猩猩的鼻子不会没闻到。
帮顶,
liangzhifa 2009-11-19
  • 打赏
  • 举报
回复
没人能解决吗?郁闷郁闷啊
liangzhifa 2009-11-19
  • 打赏
  • 举报
回复
dll是第三方提供的,要跟其他系统有接口的,所以dll不可能是我们自己开发。
windyhero1983 2009-11-19
  • 打赏
  • 举报
回复
VB调用dll,除了VB写的外,其它语言写的必须是标准的dll控件,这个做很麻烦一般人都不会花时间做这个的,你还是把这个dll转译成VB自己写个类模块最现实了。
  • 打赏
  • 举报
回复
冒是vb和delphi是仇人加对家。

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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