Solved

How to reference a Dll at runtime

Posted on 1998-12-01
13
448 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
Independent Software Vendors: 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 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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Excel - Save a copy of work book 13 96
Help me. 3 79
Automatically generate a pdf file from an excel file and email out everyday 2 78
Formula problem with Excel attachment 6 45
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

739 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