Link to home
Start Free TrialLog in
Avatar of MrQwerty
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
ASKER CERTIFIED SOLUTION
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of MrQwerty
MrQwerty

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?
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
Hi MrQwerty,

Use this instead:

Debug.Print CallByName(oMyObj,strMyFunction,Array(2,2),vbMethod)

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!
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