?
Solved

VB6 project reference

Posted on 2009-07-09
4
Medium Priority
?
165 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
[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
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 1000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
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…
Suggested Courses

764 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