Solved

How to reference a Dll at runtime

Posted on 1998-12-01
13
450 Views
Last Modified: 2012-05-04
I'm working on a program in where I get to know the name of the Dll's I'll use at runtime, and of course I can't reference it using the reference menu in Vb.

If someone needs more details e-mail me al javierma@cic.usb.ve

0
Comment
Question by:javierma
[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
  • 3
  • 3
  • 3
  • +3
13 Comments
 
LVL 3

Expert Comment

by:vbWhiz
ID: 1447730
Are these dll's interchangable - have the same functions etc that you will be using. It may be possible to accomplish this with COM & Type Libraries (.tlb).
0
 
LVL 1

Expert Comment

by:wizard2072098
ID: 1447731
Unfortunately, VB doesn't have a method for dynamically binding to a type library at run-time (at least not that I'm aware of). Alas, this would be nice, but for now you may have to relegate yourself to creating a generic interface to the DLLs for run-time binding.
0
 
LVL 4

Expert Comment

by:idcanada
ID: 1447732

Wizard2 is right,
you can not reference a DLLduring runtime.
In a compiled EXE, VB builds himself a list of available resources, which can be
seen in the object explorer.

You MUST add these references before you compile a project.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 1

Author Comment

by:javierma
ID: 1447733
I´ll give more details on the use of the Dll so you can propose an alternate answer.
The Dll's identify a group of objects wich share some common characteristics. Each Dll has the information for creating some objects like apearance and behabior. The problem is that I want to distribute the final application with only some basic objects. If the user needs extra objects he buys them and just copy the Dll (wich contains the extra objects) in a directory so when the program starts it recognizes the added Dll.

I´ve seen other programs behave like that i.e. MathLab.

Since it´s becomming more dificult than I first thought I´ll increase 50 points to the question.
0
 
LVL 4

Expert Comment

by:idcanada
ID: 1447734

As far as VB goes, you simply can NOT do that.
I know it isn't a pleasant answer.

But I would suggest making a small DLL to demonstate
and if the user wants to purchase send him the new DLL
with the same Binary Comp.


0
 
LVL 1

Expert Comment

by:muffinthedog
ID: 1447735
Wizard2 is right: see http://premium.microsoft.com/msdn/library/books/techlang/hcvb/html/loadingmodule.htm. Could get around it by using a little C DLL function to dynamically bind at runtime (why not just use some form of licensing and distribute a single DLL)
0
 
LVL 1

Author Comment

by:javierma
ID: 1447736
I found a way but is ineficient. IF the Dll is in the registry of the system I CAN use it with the function CreateObject but Vb loads some error handlers and routines that slow down my app performance. This type of declaration is knokn as late binding. I was told that in Vb6 there wasn´t this slow down problem but i only have Vb5.
0
 
LVL 3

Expert Comment

by:vbWhiz
ID: 1447737
You can create all the dll's in advance and add them to your project references. Then you can write code that uses your objects with one precaution - you must check for the dll's existance before dimming any variables as a type that might not be included. For instance, if you plan on putting the dll's in the same directory as the exe then you could write code that looks like this:

Public Sub UseMyDogObject()

If filelen(App.path & "\Dog.dll") <> 0 then
   ReallyUseDogObject
Else
   MsgBox "You must purchase the dog object from me."
End IF

End Sub

Public Sub ReallyUseDogObject()
   Dim oDog As Dog
   Set oDog = New Dog
   MsgBox Dog.Bark
   MsgBox "Etc..."
   set oDog = Nothing
End Sub

[-Note- this will not compile correctly if the dll's do not exist but if you compile this and then remove some dll's it will just not use the objects from the dll]
0
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1447738
The fast solution is to define an interface that all the DLL should support. This interface is just a public class in what might be a seperate DLL.
Every DLL should now implement this interface using the keyword implements.

Implements IMyDLLInterface

In the calling exe you can now create the object using create object and assign it to an IMyDLLInterface object

Dim dllInstance as IMyDLLInstance
set  dllInstance  = CreateObject ("Proj.Class")

Now it is early binding again.
0
 
LVL 1

Author Comment

by:javierma
ID: 1447739
Hi Mirkwood, I already tried your aproach in Vb5 and this is what hapened: Vb ctreated the object and killed it before reference it to the variable (dllInstance in your example) but this is the closest I´ve been. I don't know if is the same situation in Vb6.

Is there any way to do it in C++ and try to use it in visual?.

vbwhiz, your solution is very good but I can´t plan the objects that are going to be added in the future. I was thinking of a special module in all the Dll that tell the program which object are available in the Dll. Both of you are very close.
0
 
LVL 3

Expert Comment

by:vbWhiz
ID: 1447740
javierma, how about having an intermediate dll that contains code like my dog example. This dll would have only one class that can then create instances of the other classes from the other dlls. You could then recompile a new version of this small intermediate dll every time you create some new objects and send it along with the new dll.
0
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1447741
We use it with VB5 and it works fine.
I would try it again if I were you because this definitelly works.
0
 
LVL 13

Accepted Solution

by:
Mirkwood earned 220 total points
ID: 1447742
Sometimes, you just know you have the right answer.

We use it with VB5 and it works fine.
I would try it again if I were you because this definitelly works.
0

Featured Post

Want Experts Exchange at your fingertips?

With Experts Exchange’s latest app release, you can now experience our most recent features, updates, and the same community interface while on-the-go. Download our latest app release at the Android or Apple stores today!

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month3 days, 15 hours left to enroll

630 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