[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 259
  • Last Modified:

VB6 instantiate of DLL

Is is possible to instantiate a dll from the code rather than having to add it to the references? I have 2 groups of users that I have to accomodate and one has a DLL that I need to call and the other does not. The DLL is licensed so I can't redistribute it with my app. I want to accomodate both with one program. If I leave in the reference to the DLL then it will bomb if a user who does not have it installs the updated program that uses the DLL in the references. Any Ideas?
0
ekperdue
Asked:
ekperdue
  • 6
  • 4
1 Solution
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
you have to use late binding:

dim x as object ' instead of dim x as SomeProject.someclass
set x = createobject("SomeProject.SomeClass") ' instead of set x = new SomeProject.SomeClass

you will loose the intellisense  (when typing the class.  -> the functions don't appear)
you will loose all constants from the referenced project, so you have to either use the numerical value instead, or (re)define the enumerations as you need it.
0
 
ekperdueAuthor Commented:
Hi angelIII,

Thanks. Does this mean that if I have the DLL referenced and it does not exist on the machine that it is loaded on AND I use the code you have above that I will not get an error that the DLL was not found? Sorry, but I want to make sure that we are on the same page here.
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
>Does this mean that if I have the DLL referenced
no, you do NOT reference the DLL in the vb project at all.
if you try to load it (using the Createobject function), and error will occur that you have to trap and react on.

0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
ekperdueAuthor Commented:
What about in the case of an exe that I might normally reference under 'project\references' from the menu?
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
? you don't reference .exe files, except maybe activex exe files, which can be handled the same way as DLLs.
0
 
ekperdueAuthor Commented:
Right. one of them is an activex exe that is usually referenced with 'project\references'. So, just to make sure that I understand. I do not have to reference the activex exe or DLL in the 'project\references' in VB6 if I use the code that you mentioned initially?

Thanks for your help.
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
correct
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
PS: note however that you will loose the abitily to handle the events from such dll classes directly.
the workaround is (usually) to implement a worker DLL that contains a EventRaising class that will not change ever more, which is used to raise and handle events...
0
 
ekperdueAuthor Commented:
Could you give an example as to how the worker DLL might look (or reference some online examples) just so that I canbe sure that I have it..

Thanks.
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
This is all:

Public Event GenericEvent ( byval EventName as string, byval EventInfo as string, byval EventData as string, byref EventReturn as variant )

Public Sub DoRaiseEvent ( byval EventName as string, byval EventInfo as string, byval EventData as string , byref EventReturn as variant )
  Raiseevent GenericEvent (EventName, Eventinfo, EventData, EventReturn )
End Sub


Now, that is a generic thing, which allows you to do "everything" what you can do with events (at least, I never needed more)
The EventName and EventInfo parameters should be clear.
EventData is to pass additional Data (parameters) around, I use XML formatted string for that.
EventReturn is Byref to permit to get data passed back to the "caller".

Put that into a single public class into a dll project, and reference it from "all" your other projects.
All objects that want to use events should initiate such an object as property or accept to get an object to send events to.
This way, you can raise events both ways easily.

I once implemented additionally a class around this to raise events across machines using a winsocket communication.

Hope this helps

0

Featured Post

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.

  • 6
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now