• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 137
  • Last Modified:

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
0
MrQwerty
Asked:
MrQwerty
  • 2
  • 2
  • 2
  • +1
1 Solution
 
Éric MoreauSenior .Net ConsultantCommented:
see CallByName in the VB help.
0
 
MrQwertyAuthor Commented:
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?
0
 
Éric MoreauSenior .Net ConsultantCommented:
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
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
TimCotteeCommented:
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
0
 
TimCotteeCommented:
Too slow again!
0
 
MrQwertyAuthor Commented:
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?
0
 
fluglashCommented:
try to use API CallWindowProc or something like that
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 2
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now