?
Solved

Dynamically calling functions of a ActiveX Dll

Posted on 2003-03-13
7
Medium Priority
?
135 Views
Last Modified: 2010-05-01
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
Comment
Question by:MrQwerty
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 460 total points
ID: 8126978
see CallByName in the VB help.
0
 

Author Comment

by:MrQwerty
ID: 8127006
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
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 8127061
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 43

Expert Comment

by:TimCottee
ID: 8127071
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
 
LVL 43

Expert Comment

by:TimCottee
ID: 8127072
Too slow again!
0
 

Author Comment

by:MrQwerty
ID: 8127575
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
 
LVL 7

Expert Comment

by:fluglash
ID: 8127640
try to use API CallWindowProc or something like that
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question