ACC2: Sample Function for Retrieving File Version Information

ID: Q128810


The information in this article applies to:


SUMMARY

Advanced: Requires expert coding, interoperability, and multiuser skills.

This article contains a sample user-defined Access Basic function you can use to check the file version information stored within most files.

This article assumes that you are familiar with Access Basic and with creating Microsoft Access applications using the programming tools provided with Microsoft Access. For more information on Access Basic, please refer to the "Building Applications" manual.


MORE INFORMATION

Most files used by Windows-based applications contain a version stamp. You cannot check this version stamp within Microsoft Access, but you can check it by using Windows API calls within Access Basic.

The following example demonstrates a sample user-defined function that you can use to check the version number (if available) of a file.

NOTE: You may have some Microsoft Windows API functions defined in an existing Microsoft Access library; therefore, your declarations may be duplicates. If you receive a duplicate procedure name error message, remove or comment out the declarations statement in your code.

NOTE: In the following sample code, an underscore (_) at the end of a line is used as a line-continuation character. Remove the underscore from the end of the line when recreating this code.

  1. Open the sample database NWIND.MDB.


  2. Create a new module and add the following code to the Declarations section:
    
          Type FileInfo
             wLength            As Integer
             wValueLength       As Integer
             szKey              As String * 16
             dwSignature        As Long
             dwStrucVersion     As Long
             dwFileVersionMS    As Long
             dwFileVersionLS    As Long
          End Type
    
    
          Declare Function GetFileVersionInfo% Lib "Ver.dll" (ByVal FileName$,_
               ByVal dwHandle&, ByVal cbBuff&, ByVal lpvData$)
          Declare Function GetFileVersionInfoSize& Lib "Ver.dll" (ByVal_
               FileName$, dwHandle&)
          Declare Sub hmemcpy Lib "kernel" (hpvDest As Any, hpvSrc As Any,_
               ByVal cbBytes&) 


  3. Add the following two functions in the module:
    
          Function LOWORD (x As Long) As Integer
             LOWORD = x And &HFFFF&
             'Low 16 bits contain Minor revision number.
          End Function
    
          Function HIWORD (x As Long) As Integer
             HIWORD = x \ &HFFFF&
             'High 16 bits contain Major revision number.
          End Function 


  4. Save the module and create a new form.


  5. Add a text box called Fname to the form.


  6. Add a command button to the form, and add the following code to the command button's OnClick event procedure:
    
          Dim x As FileInfo
          Dim FileVer As String
          Dim FileName As String
    
          '*** Get Version Information If Available ****
          FileVer = ""
          FileName = Me![FName]
          BufSize& = GetFileVersionInfoSize(FileName, dwHandle&)
          If BufSize& = 0 Then
             MsgBox "Invalid File Name or no Version information available"
             Exit Sub
          End If
          lpvData$ = Space$(BufSize&)
          r% = GetFileVersionInfo(FileName, dwHandle&, BufSize&, lpvData$)
          hmemcpy x, ByVal lpvData$, Len(x)
    
          '**** Parse File Version Number ****
          FileVer = Trim$(Str$(HIWORD(x.dwFileVersionMS))) + "."
          FileVer = FileVer + Trim$(Str$(LOWORD(x.dwFileVersionMS))) + "."
          FileVer = FileVer + Trim$(Str$(HIWORD(x.dwFileVersionLS))) + "."
          FileVer = FileVer + Trim$(Str$(LOWORD(x.dwFileVersionLS)))
    
          MsgBox FileVer, 64, "Version of " & FileName 


  7. To use the function, view the form in Form view and type a valid path and filename in the Fname text box. The following lines are examples of valid paths and filenames:
    
          C:\WINDOWS\SYSTEM\USER.EXE
          C:\ACCESS\MSACCESS.EXE 


  8. Choose the command button to see the version displayed in a message box.



REFERENCES

For more information about using Windows API calls, please see the "Visual Basic Programmer's Guide to the Windows API," pages 572-575.


Keywords          : kbprg 
Version           : 2.0
Platform          : WINDOWS 
Issue type        : kbinfo 

Last Reviewed: April 8, 1999