Solved

VB6 project reference

Posted on 2009-07-09
4
158 Views
Last Modified: 2013-11-26
Is it possible to include a project reference to a dll in a VB6 project, and for the exe created from the project to run successfully without the dll on the users machine. The dll is a library of objects/functions that will be called only when the dll exists on the users machine, and otherwise the code create no objects using the dll. It appears though that windows checks for the dll at program start-up and bombs if it doesn't find it.

Reason I 'd like to include the dll is so I can code with early-binding/intellisense.

thanks.
0
Comment
Question by:bmutch
  • 2
  • 2
4 Comments
 
LVL 8

Expert Comment

by:stefanx
ID: 24817221
If you reference the Automation object in your VB Project, then the code is early bound when you compile and your exe will not run if the dll is not present. To prevent this, do NOT include the DLL reference in your VB Code, and use CreateObject to instantiate your Automation object dynamically.

Let's take an example where you want to access ADO, but don't know what version (if any) might be on your client's machine. Then, first of all, do NOT reference Microsoft ADO in your project. In your VB code, do the following

Sub DoIt
  Dim DBC AS Object
  Const ComponentName = "ADODB.Connection"

  On Local Error Resume Next
  Err.Clear
  Set DBC = CreateObject(ComponentName)
  If Err <> 0 then
    MsgBox "Sorry, ADO is not installed on this computer"
    Exit Sub
  End If
  MsgBox "The ADO Version installed on your machine is " & DBC.Version
  Set DBC = Nothing
End Sub
 
0
 

Author Comment

by:bmutch
ID: 24817396
yes, I know I can late reference it, and will do so if I have to. I guess you answered my question though. I wanted to add the reference so I could have early binding and intellisense, and still be able to run the program on a machine without the dll installed because I have a way of knowing if the dll is not installed and in my code I would not create any objects from the dll if it is not present. But apparently the program will not even run because it checks at startup to see if the dll is present?
0
 
LVL 8

Accepted Solution

by:
stefanx earned 250 total points
ID: 24817663
That's right - if it is early bound it tries to load the DLL on startup of the exe. No DLL, no starting of the exe.
0
 

Author Closing Comment

by:bmutch
ID: 31601784
thanks.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…

707 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now