FIXVBPRef Tool


Overview

Visual Basic 6 applications store references to type libraries in the project (.vbp) file.  VB allows you to link projects by setting references via the Project/References menu option.  When you build a VB application that does not have binary compatibility enabled, VB will generate a new GUID for the typelib.   Now when you wish to build any dependent VB projects, you must first remove the previous reference the old typelib and recreate the reference to the new typelib.

When building a large VB project, this process can take quite a long time.  FIXVBPRef is a tool that will automatically fix missing typelib references for you.

How It Works

In the VBP file, typelib references are stored in the following format

Reference=*\G{2E4F4861-542D-11D2-8B41-00C04F991474}#1.0#0#..\..\..\..\DLLs\AdStatusEventsSvr.dll#AdStatusEventsSvr 1.0 Type Library

The reference line is a # delimited string containing the following elements

  1. GUID of the typelib
  2. typelib version
  3. ?
  4. Relative path to the typelib file (on the machine where the vbp file was created)
  5. Description of the typelib

To fix an invalid reference to a typelib, FIXVBPRef does the following

  1. Extract the relative path of the typelib file from the reference string
  2. Load the typelib
  3. Get the GUID of the typelib using the ITypeLib interface
  4. Replace the GUID on the reference string with the GUID from the typelib
  5. Write the corrected reference string to the output file

NOTE: FIXVBPRef will attempt to update the GUID of all referenced components, including some that may never change, therefore it must be able to load each referenced typelib.

Typelib Location

When the vbp file was created, the typelib locations are stored using a relative path.  In most cases, this allows for better location transparency since most developers tend to use the same directory structure on a project by project basis.  However, there are many cases where the relative path fails to locate the typelib correctly because it may be located on a different drive or directory.  FIXVBPRef will first attempt to load the typelib using the relative path stored in the vbp file.  If that fails it will search in order

Project BIN Directory

Most projects contain a BIN directory where the DLL and EXE files are written to.  Some project further segregate binary components into subdirectories according to function or location.  For example

C:\MyProject    - Project root
        \Source    - Root of source directories
        \Test        - Root of test directories
        \Bin          - Root of bin directories
            \Client    - Contains client components and applications
            \COM+    - Contains COM+ applications
            \ASP        - Contains ASP scripts

When FIXVBPRef cannot find a typelib it looks at the Bin root you specify as an argument on the command line and will recursively search the bin directory and all child directories for the desired typelib.

FIXVBPRef.OPT

If you need to reference a component typelib that is not in the bin root, you can place a text file in the bin root directory that contains a list of directories (one per line) to recursively search as well.  For example

(Sample FIXVBPRef.OPT)
C:\MyComponents\
C:\SomeThirdPartyComponent\

FIXVBPRef will look for the FIXVBPRef.opt file in the project root bin directory.

Command Line Options

FIXVBPREF MyProject.vbp [MyBinDir]

 Building VB Projects using NMAKE

Using a tool like FIXVBPRef you can completely automate builds of VB projects.

Build Environment

Sample Makefile

The sample makefile below is used to build the AdPublisher component of the Island Hopper Classifieds COM+ Sample Application

#VB Project Make File
PROJNAME=AdPublisher
PROJECT=$(PROJNAME).vbp
BINROOT=$(MSSDK)Samples\Com\Application_Samples\Island_Hopper_Classifieds\DLLs
TARGET="$(BINROOT)\$(PROJNAME).dll"
VBLOG="$(BINROOT)\VBBUILD.LOG"

#Modify the line below if you installed VB in a non-standard location
VB6="%ProgramFiles%\Microsoft Visual Studio\vb98\vb6.exe"

ALL : CLEAN $(TARGET) POSTCLEAN

CLEAN :
    -@erase $(TARGET)

$(TARGET) : $(PROJECT)
    fixvbpref $(PROJECT) $(BINROOT)
    $(VB6) /make /out $(VBLOG) $(PROJECT)

POSTCLEAN :
    -@erase $(BINROOT)\$(PROJNAME).exp
    -@erase $(BINROOT)\$(PROJNAME).lib

Support / General Info

FIXVBPRef is provided as an unsupported application sample.