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
Solved

VB6 project reference

Posted on 2009-07-09
4
161 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

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…
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 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…

809 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