How to Obtain the Version of VBRUN300.DLL

Last reviewed: March 7, 1996
Article ID: Q129875
The information in this article applies to:
  • Standard, Professional, and Enterprise Editions of Microsoft Visual Basic, 16-bit and 32-bit, for Windows, version 4.0
  • Standard and Professional Editions of Microsoft Visual Basic for Windows, version 3.0

SUMMARY

The function VBGetVersion(), documented in the Visual Basic API Reference file, returns the constant for version 3.0 in both Versions 3.0 and 4.0 of Visual Basic. This return value was preserved in order to maintain compatibility with many existing .VBX files that check for a version constant. This article describes a technique you can use to obtain the true version of Visual Basic.

MORE INFORMATION

At address SS:0020 (Hex), Visual Basic will load the address of a function table when a Visual Basic program is running. This address is always fixed, although the address will depend on whether the program is run from the design environment or being run as an executable. VBRUN300.DLL contained in Version 3.0 always loads an address different from the version 4.0 equivalent. The following table details these addresses. The 16-Bit Hexadecimal address found at SS:0020 for a Visual Basic program:

   Mode                    Version 3.0    Version 4.0
   --------------------------------------------------
   Design/Run Mode         142E           39D2
   Run as Executable       01ED           1A90

These addresses are always fixed, so you can create a simple DLL to distinguish the versions of Visual Basic.

It is important to note that the addresses listed in this article will probably change in any future releases of Visual Basic. Therefore a control developer should account for the fact that the technique described below may provide incorrect results with any future releases.

Step-by-Step Example

  1. Start a new project to make a DLL. In this example, Visual C++ version 1.52 was used as the compiler. First create a DEF file as below:

       LIBRARY              GetVersionVB
       DESCRIPTION          'GetVersion Can be called from Visual Basic'
       EXETYPE              WINDOWS 3.1
       CODE                 PRELOAD MOVEABLE DISCARDABLE
       DATA                 PRELOAD MOVEABLE SINGLE
       HEAPSIZE             4096
       EXPORTS
                            GetVersionVB @1
    
    

  2. Create a new source code file containing the following code. This code retrieves the address at SS:0020 (Hex) and compares it with the predefined values:

       #include <windows.h>
       #include <vbapi.h>
    
       int FAR PASCAL LibMain (HANDLE hInstance, WORD wDataSeg, WORD wHeapSize,
          LPSTR lpszCmdLine)
       {
          if (wHeapSize > 0)
             UnlockData (0);  //Unlocks the data segment of the library.
          return 1;
       }
    
       WORD FAR PASCAL _export GetVersionVB( void )
       {
          unsigned short nVerConst;
          nVerConst=VBGetVersion(); //Call VB API
    
          if (nVerConst==VB100_VERSION)  //Constant VB100_VERSION in vbapi.h
             return 1;
    
          if (nVerConst==VB200_VERSION)
             return 2;
    
          if (nVerConst==VB300_VERSION)
          {
    
             WORD SS20;
    
             _asm  {                 //Retrieve function table address at SS20
                   mov ax, SS:[0x0020];
                   mov SS20, ax;
                   }
    
             if ( (SS20==0x01ED) || (SS20==0x142E) )
             {
                return 3;
             }
    
             if ( (SS20==0x39D2) || (SS20==0x1A90) )
             {
                return 4;
             }
          }
    
    // If we reach this point, none of the addresses were correct
    // possibly indicating a new release of VB - so the code returns 0
    
    
return 0; }

   int FAR PASCAL _export WEP(int nParam)
   {
      return 1;
   }

  • Add the VBAPI.LIB to the list of libraries to be linked into the project. To accomplish this in Visual C++ version 1.52:

    a. Choose Project from the Options menu.

    b. Choose the Linker button.

    c. Select the Input category.

    d. Add VBAPI.LIB.

    e. Build the DLL, and name it FINDVER.DLL.

    f. Move FINDVER.DLL into the WINDOWS\SYSTEM directory.

  • Call the .DLL file from a Visual Basic program. To do this:

    a. Create a new project in Visual Basic. Form1 is created by default.

    b. Place the declaration for the DLL inside the Declarations section

          for the form:
    

          Declare Function GetVersionVB Lib "findver.dll" () As Integer
    

    c. Place a command button (Command1) on Form1, and add the following

          code to the Command1_Click event to call the DLL function:
    

          MsgBox Str(GetVersionVB())
    

    d. Press the F5 key to run the program, and click the Command1 button

          to see a message box listing the version of Visual Basic.
    


  • Additional reference words: 3.00 4.00 vb4win vb4all
    KBCategory: kbenv kbprg kbcode
    KBSubcategory: EnvtRun


    THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

    Last reviewed: March 7, 1996
    © 1998 Microsoft Corporation. All rights reserved. Terms of Use.