vb动态加载dll的,我加载的函数是int max(int *a,int b)参数怎么传递,
a为数组,存放的整数,b为数组中整数的个数
周文星 (用户名:SupermanKing) 他好像以前写过这个文章,但是加载的函数是字符串文本。我现在的函数是求数组中最大值,忘高人指点,给出源代码。
a为数组,存放的整数,b为数组中整数的个数
周文星 (用户名:SupermanKing) 他好像以前写过这个文章,但是加载的函数是字符串文本。我现在的函数是求数组中最大值,忘高人指点,给出源代码。
解决方案 »
- 请问VB下,WINMD5程序对比两个文件的MD5值怎么样实现?
- 程序直接运行正常,但是编译成.exe就出错,怎么回事啊?
- realone 控件的问题
- 请问这个很简单的SQL语句怎么写啊?
- 怎样:把界面上控件MS Chart中的统计图形 ,存为一个图形文件
- 关于图标的问题
- vb中怎么动态生成按钮
- 怎么参照一个闭合凸或凹多边形,做一个每边平行放大或缩小的多形(也就是多边形的等距线问题)
- 重新开个贴吧,抓包问题,帮帮小妹
- ▲高分求助::::::::::::::::::::::::::我在使用datacombo控件地时候发现一个问题,当不改变其它的值,datacombo的值无法改变!RecordSource是一个查询语句(▲大侠们,救我啊!!!!!!!)
- select语句问题
- xml怎么通过xsd文件来校验
Private Declare Function Max Lib "a.dll" Alias "MaxA" (ByRef a() As Double, ByVal L As Integer) As DoublePrivate Sub Form_Load()
Dim a(1 To 10) As Double
Dim i As Integer
Dim MaxNum As Double
For i = 1 To 10
a(i) = CDbl(Rnd * 10)
Next i
MaxNum = Max(a, 10)
End Sub
我我现在的目的是我在一个文件夹下有许多dll,我的程序运行后,我通过对话框选择想用的dll,有兴趣的话加我qq,675484832。继续聊
callbyname,这是vb6中新增的函数,可以在程序中动态调用dll,然后执行dll含的函数和方法,具体参照上面链接
Option Explicit
Private MyPropValue As Integer
Public Function Multiply(x As Integer, y As Integer) As Integer
Multiply = x * y
End Function
Public Property Get MyProperty() As Variant
MyProperty = MyPropValue
End Property
Public Property Let MyProperty(ByVal vNewValue As Variant)
MyPropValue = vNewValue
End Property
Private Sub Test()
Dim myclass As New CMyObject
Dim sum As Integer
Dim prop As Integer
' Example of calling a method with CallByName
' equivalent to -- sum = myclass.Multiply(12, 12)
sum = CallByName(myclass, "Multiply", VbMethod, 12, 12)
MsgBox sum
' Example of a property let with CallByName
' equivalent to -- myclass.MyProperty = 5
CallByName myclass, "MyProperty", VbLet, 5
' Example of a property get with CallByName
' equivalent to -- prop = myclass.MyProperty
prop = CallByName(myclass, "MyProperty", VbGet)
MsgBox prop
End Sub
Private Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As LongPrivate Declare Function GetProcAddress Lib "kernel32" (ByVal hModule As Long,ByVal lpProcName As String) As LongPrivate Declare Function GetProcAddress Lib "kernel32" (ByVal hModule As Long, ByVal lpProcName As String) As Long Public Function MyFunction(strDll As String, strFunction As String) As Long
Dim lngRtn As Long, lngFunAddr As Long
lngRtn = LoadLibrary(strDll) 'strDll 是你需要调用的dll
If lngRtn = 0 Then MsgBox "Err.": End ’调用失败就退出了
lngFunAddr = GetProcAddress(lngRtn, strFunction) ’如果成功则
If lngFunAddr = 0 Then MsgBox "Err.": End
MyFunction = lngFunAddr
End FunctionPrivate Sub main()
Dim lngRtn As Long
lngRtn = 0
lngRtn = MyFunction("kernel32.dll", "Beep")
MsgBox "函数地址为:" & " " & cstr(lngRtn)
End Sub
http://topic.csdn.net/u/20110329/10/78f7baa9-d526-4a6f-8e23-6141d9bb76d3.html
Dim n As Integer, MinVal
On Error Resume Next
MinVal = Vals(0)
For n = 1 To UBound(Vals)
If Vals(n) < MinVal Then MinVal = Vals(n)
Next n
Minimum = MinVal
End Function
Private Function Maximum(ParamArray Vals())
Dim n As Integer, MaxVal
On Error Resume Next
MaxVal = Vals(0)
For n = 1 To UBound(Vals)
If Vals(n) > MaxVal Then MaxVal = Vals(n)
Next n
Maximum = MaxVal
End Function
http://topic.csdn.net/u/20111007/18/284d0b5a-1945-40d8-aaa7-8d13afba5196.html
还有,如果是Stdcall的话,要用dumpbin看看DLL中函数真正的名字,可能会变成_max@8之类的另外如果用我的方法调用你的DLL,应该这样使用Dim hModule As Long, pProc As Long,p(1) as Long
hModule = LoadLibrary("????????")
pProc = GetProcAddress(hModule, "???????")
dim a as integer ,b as integer
a=111
b=123
If pProc <> 0 Then
p(0)=varptr(a) '第一个参数
p(1)=b '第2个参数
Form1.Print CallProc(pProc, VarPtr(p(1)),2)
Else
MsgBox "err"
End If
FreeLibrary hModule哦,还有我的调用方法支持的是LONG作为参数的,不知道int为参数行不行
http://topic.csdn.net/u/20080928/15/287c677b-69e6-432e-9f77-ee58b3fa619f.html