delphi里抛出的方法是 SetUpLoad (funcA :TfuncA)
我在VB的写法是:
Declare Sub SetUpLoad Lib "East.Dll" (ByVal funcA As Long) 声明函数
Public Sub funcA(Dev_id As Integer, serial As String, ip As String) ‘回调函数 以下是简单代码
Mainform.ClockID.Text = Dev_id
Mainform.serial.Text = serial
Mainform.ip.Text = ip
End Sub
call SetUpLoad(AddressOf SetUpLoad) ‘调用函数
运行的时候,程序没有反映,不知道我这样写错在那里,哪位大哥可以指点一下!谢谢。
13 个解决方案
#1
' Mainform.ClockID.Text = Dev_id
' Mainform.serial.Text = serial
' Mainform.ip.Text = ip
'End Sub
改为如下面的看看
Declare Function SysAllocString Lib "oleaut32.dll" (ByVal pOlechar As Long) As String
Public Sub funcA(byval Dev_id As Integer, byval serial As long, byvalip As long) ‘回调函数 以下是简单代码
Mainform.ClockID.Text = Dev_id
Mainform.serial.Text = SysAllocString(serial )
Mainform.ip.Text = SysAllocString (ip)
End Sub
#2
谢谢,我这样写还是不行。。想问一下,我这样调用这个DLL的写法有没有问题?
#3
call SetUpLoad(AddressOf
SetUpLoad) ‘调用函数
-->
call SetUpLoad(AddressOf funcA)
-->
call SetUpLoad(AddressOf funcA)
#4
谢谢,这个是我发帖时候的BUGEE!
#5
请把你的代码贴详细一点呀,这样没法看
#6
vb中无法调用有回调函数的DLL,这个我之前也折腾过一段时间。查了N多资料,大多都是牛头不搭马嘴的,最后有一篇文章明确说到,有回调函数的DLL,VB无法调用,它给出的方法却是怎么用C++封装DLL的接口重新编译的。
#7
谢谢的回复,这个问题暂时放一放,我在修改DLL。。还有一个问题,就是传结构体变量的。
Type myREC
CardID As Long
EmpID As Long
time As Long
End Type
Declare Function GetThree Lib "MyLib.dll" (FmyREC As myREC) As Long
这个是获取最后三次消费记录的 卡号、工号 时间。
Dim mrs(0 to 2) As GetThree
Dim ret As Long
'ret = GetThree(mrs)
这样写,却得不到数据,请问错在那里?
#8
Type myREC
CardID As Long
EmpID As Long
time As Long
End Type
'建议你用long
Declare Function GetThree Lib "MyLib.dll" (FmyREC As long) As Long
Const LONG_SIZE = 4
Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _
(lpDestination As Any, _
lpSource As Any, _
ByVal lLength As Long)
Dim vCardId As Long
Dim vEmpId As Long
Dim vTime As Long
Dim vMyPtr As Long
Dim vRc As Long
vRc = GetThree(vMyPtr)
Dim FmyRec(0 To 2) As myREC
CopyMemory FmyRec, ByVal vMyPtr, LONG_SIZE
#9
朋友,在“Dim FmyRec(0 To 2) As myREC”提示类型不匹配。
#10
CHRL
,方便加我QQ吗?14308807
,方便加我QQ吗?14308807
#11
不好意思,我这里工作期间只能用MSN:chrlinux@hotmail.com
#12
你不不知道,不代表别人不知道.搜索不是万能的.
'窗体
Private Sub Command1_Click()
EnumWindows AddressOf EnumWinProc, 0&
End Sub
'模块
Option Explicit
Public Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal LPARAM As Long) As Long
Public Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
Public Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Dim a As Long
Public Function EnumWinProc(ByVal hwnd As Long, ByVal p As Long) As Boolean
Dim s As String
Dim ret As Long
ret = GetWindowTextLength(hwnd)
s = Space(ret)
ret = GetWindowText(hwnd, s, ret)
Debug.Print s
EnumWinProc = True
End Function
#13
把结构传递给DLL,在接口要分清传递的应该是指针byref,在DLL里面操作的也是指针.
比如Private Declare Function GetCurrentPositionEx Lib "gdi32" Alias "GetCurrentPositionEx" (ByVal hdc As Long, lpPoint As POINTAPI) As Long
就是结构.
你的回调没反应,需要看看你的DLL里面怎么处理的,你大可以在IDE环境,在回调Public Sub funcA(Dev_id As Integer, serial As String, ip As String) 里面下断点,看看程序执行没有.
参数那里也是问题,你什么的funcA是byref,参数都是传递的指针,地址.DLL是这么处理的?
枚举窗口那个例子,为什么系统给的参数方式都是byval?
比如Private Declare Function GetCurrentPositionEx Lib "gdi32" Alias "GetCurrentPositionEx" (ByVal hdc As Long, lpPoint As POINTAPI) As Long
就是结构.
你的回调没反应,需要看看你的DLL里面怎么处理的,你大可以在IDE环境,在回调Public Sub funcA(Dev_id As Integer, serial As String, ip As String) 里面下断点,看看程序执行没有.
参数那里也是问题,你什么的funcA是byref,参数都是传递的指针,地址.DLL是这么处理的?
枚举窗口那个例子,为什么系统给的参数方式都是byval?
#1
' Mainform.ClockID.Text = Dev_id
' Mainform.serial.Text = serial
' Mainform.ip.Text = ip
'End Sub
改为如下面的看看
Declare Function SysAllocString Lib "oleaut32.dll" (ByVal pOlechar As Long) As String
Public Sub funcA(byval Dev_id As Integer, byval serial As long, byvalip As long) ‘回调函数 以下是简单代码
Mainform.ClockID.Text = Dev_id
Mainform.serial.Text = SysAllocString(serial )
Mainform.ip.Text = SysAllocString (ip)
End Sub
#2
谢谢,我这样写还是不行。。想问一下,我这样调用这个DLL的写法有没有问题?
#3
call SetUpLoad(AddressOf
SetUpLoad) ‘调用函数
-->
call SetUpLoad(AddressOf funcA)
-->
call SetUpLoad(AddressOf funcA)
#4
谢谢,这个是我发帖时候的BUGEE!
#5
请把你的代码贴详细一点呀,这样没法看
#6
vb中无法调用有回调函数的DLL,这个我之前也折腾过一段时间。查了N多资料,大多都是牛头不搭马嘴的,最后有一篇文章明确说到,有回调函数的DLL,VB无法调用,它给出的方法却是怎么用C++封装DLL的接口重新编译的。
#7
谢谢的回复,这个问题暂时放一放,我在修改DLL。。还有一个问题,就是传结构体变量的。
Type myREC
CardID As Long
EmpID As Long
time As Long
End Type
Declare Function GetThree Lib "MyLib.dll" (FmyREC As myREC) As Long
这个是获取最后三次消费记录的 卡号、工号 时间。
Dim mrs(0 to 2) As GetThree
Dim ret As Long
'ret = GetThree(mrs)
这样写,却得不到数据,请问错在那里?
#8
Type myREC
CardID As Long
EmpID As Long
time As Long
End Type
'建议你用long
Declare Function GetThree Lib "MyLib.dll" (FmyREC As long) As Long
Const LONG_SIZE = 4
Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _
(lpDestination As Any, _
lpSource As Any, _
ByVal lLength As Long)
Dim vCardId As Long
Dim vEmpId As Long
Dim vTime As Long
Dim vMyPtr As Long
Dim vRc As Long
vRc = GetThree(vMyPtr)
Dim FmyRec(0 To 2) As myREC
CopyMemory FmyRec, ByVal vMyPtr, LONG_SIZE
#9
朋友,在“Dim FmyRec(0 To 2) As myREC”提示类型不匹配。
#10
CHRL
,方便加我QQ吗?14308807
,方便加我QQ吗?14308807
#11
不好意思,我这里工作期间只能用MSN:chrlinux@hotmail.com
#12
你不不知道,不代表别人不知道.搜索不是万能的.
'窗体
Private Sub Command1_Click()
EnumWindows AddressOf EnumWinProc, 0&
End Sub
'模块
Option Explicit
Public Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal LPARAM As Long) As Long
Public Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
Public Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Dim a As Long
Public Function EnumWinProc(ByVal hwnd As Long, ByVal p As Long) As Boolean
Dim s As String
Dim ret As Long
ret = GetWindowTextLength(hwnd)
s = Space(ret)
ret = GetWindowText(hwnd, s, ret)
Debug.Print s
EnumWinProc = True
End Function
#13
把结构传递给DLL,在接口要分清传递的应该是指针byref,在DLL里面操作的也是指针.
比如Private Declare Function GetCurrentPositionEx Lib "gdi32" Alias "GetCurrentPositionEx" (ByVal hdc As Long, lpPoint As POINTAPI) As Long
就是结构.
你的回调没反应,需要看看你的DLL里面怎么处理的,你大可以在IDE环境,在回调Public Sub funcA(Dev_id As Integer, serial As String, ip As String) 里面下断点,看看程序执行没有.
参数那里也是问题,你什么的funcA是byref,参数都是传递的指针,地址.DLL是这么处理的?
枚举窗口那个例子,为什么系统给的参数方式都是byval?
比如Private Declare Function GetCurrentPositionEx Lib "gdi32" Alias "GetCurrentPositionEx" (ByVal hdc As Long, lpPoint As POINTAPI) As Long
就是结构.
你的回调没反应,需要看看你的DLL里面怎么处理的,你大可以在IDE环境,在回调Public Sub funcA(Dev_id As Integer, serial As String, ip As String) 里面下断点,看看程序执行没有.
参数那里也是问题,你什么的funcA是byref,参数都是传递的指针,地址.DLL是这么处理的?
枚举窗口那个例子,为什么系统给的参数方式都是byval?