MrQwerty
asked on
Dynamically calling functions of a ActiveX Dll
I have dll's I want to use dynamically.
dim strMyDll as string
strmydll = "Object1.Class1"
I can create a object eg
set oMyObj = createobject(strMyDll)
but how can I do something like this
dim strMyFunction = "Multiply"
debug.print oMyObj.strMyFunction(2,2) <-- instead of oMyObj.Multilply ???
Where
public Multiply(lngA as long,lngB as long) as long
Multiply = lngA*lngB
end function
Thanks a lot in advance
dim strMyDll as string
strmydll = "Object1.Class1"
I can create a object eg
set oMyObj = createobject(strMyDll)
but how can I do something like this
dim strMyFunction = "Multiply"
debug.print oMyObj.strMyFunction(2,2) <-- instead of oMyObj.Multilply ???
Where
public Multiply(lngA as long,lngB as long) as long
Multiply = lngA*lngB
end function
Thanks a lot in advance
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
It is possible. See this small test:
In class1:
Public Sub P1()
MsgBox "P1"
End Sub
Public Function F1(ByVal P1 As Integer, ByVal p2 As Integer) As Integer
MsgBox "F1"
F1 = P1 + p2
End Function
In Form1:
Private Sub Command1_Click()
Dim x As New Class1
CallByName x, "P1", VbMethod
End Sub
Private Sub Command2_Click()
Dim x As New Class1
MsgBox CallByName(x, "F1", VbMethod, 2, 2)
End Sub
In class1:
Public Sub P1()
MsgBox "P1"
End Sub
Public Function F1(ByVal P1 As Integer, ByVal p2 As Integer) As Integer
MsgBox "F1"
F1 = P1 + p2
End Function
In Form1:
Private Sub Command1_Click()
Dim x As New Class1
CallByName x, "P1", VbMethod
End Sub
Private Sub Command2_Click()
Dim x As New Class1
MsgBox CallByName(x, "F1", VbMethod, 2, 2)
End Sub
Hi MrQwerty,
Use this instead:
Debug.Print CallByName(oMyObj,strMyFun ction,Arra y(2,2),vbM ethod)
Where Array(2,2) is an array of arguments to the function. You could create this variant array first with your arguments of course and simply pass the array in that parameter.
Tim Cottee MCSD, MCDBA, CPIM
http://www.timcottee.tk
Brainbench MVP for Visual Basic
http://www.brainbench.com
Experts-Exchange Advisory Board Member
Use this instead:
Debug.Print CallByName(oMyObj,strMyFun
Where Array(2,2) is an array of arguments to the function. You could create this variant array first with your arguments of course and simply pass the array in that parameter.
Tim Cottee MCSD, MCDBA, CPIM
http://www.timcottee.tk
Brainbench MVP for Visual Basic
http://www.brainbench.com
Experts-Exchange Advisory Board Member
Too slow again!
ASKER
Thanks, I've spend an hour looking in msdn but its rubbish to stuff like this. I knew it was possible. Do you want the points?
try to use API CallWindowProc or something like that
ASKER