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 [解决办法]
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 [解决办法] Option Explicit 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 Long
Private 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 Function
Private Sub main() Dim lngRtn As Long lngRtn = 0 lngRtn = MyFunction("kernel32.dll", "Beep")
Private Function Minimum(ParamArray Vals())Dim n As Integer, MinValOn Error Resume Next MinVal = Vals(0) For n = 1 To UBound(Vals) If Vals(n) < MinVal Then MinVal = Vals(n) Next n Minimum = MinValEnd FunctionPrivate Function Maximum(ParamArray Vals())Dim n As Integer, MaxValOn Error Resume Next MaxVal = Vals(0) For n = 1 To UBound(Vals) If Vals(n) > MaxVal Then MaxVal = Vals(n) Next n Maximum = MaxValEnd Function [解决办法] 看看我写的这个 http://topic.csdn.net/u/20111007/18/284d0b5a-1945-40d8-aaa7-8d13afba5196.html [解决办法] 6楼是vb.net,vb6用不了的吧 [解决办法] 你的DLL是STDCALL的么?不是的话压栈方式是不同的 还有,如果是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