dll version information

How do I get the version in formation for a dll file from within VB.

I want to do something like:

DLLFile.Filename = "C:\Test.dll"
debug.print DLLFilename.VersionNumber

Thanks.
TheNuggetAsked:
Who is Participating?
 
aswirthmConnect With a Mentor Commented:
Here is some code using api function.
You need a type declaration and some api-declares. Paste them in a global module. It works fine:

Declare Function GetFileVersionInfo Lib "Version.dll" Alias _
   "GetFileVersionInfoA" (ByVal lptstrFilename As String, ByVal _
   dwhandle As Long, ByVal dwlen As Long, lpData As Any) As Long
   
Declare Function GetFileVersionInfoSize Lib "Version.dll" Alias _
   "GetFileVersionInfoSizeA" (ByVal lptstrFilename As String, _
   lpdwHandle As Long) As Long
   
Declare Function VerQueryValue Lib "Version.dll" Alias _
   "VerQueryValueA" (pBlock As Any, ByVal lpSubBlock As String, _
   lplpBuffer As Any, puLen As Long) As Long
   
Declare Sub MoveMemory Lib "kernel32" Alias "RtlMoveMemory" _
   (dest As Any, ByVal Source As Long, ByVal length As Long)

Type VS_FIXEDFILEINFO
   dwSignature As Long
   dwStrucVersionl As Integer     '  e.g. = &h0000 = 0
   dwStrucVersionh As Integer     '  e.g. = &h0042 = .42
   dwFileVersionMSl As Integer    '  e.g. = &h0003 = 3
   dwFileVersionMSh As Integer    '  e.g. = &h0075 = .75
   dwFileVersionLSl As Integer    '  e.g. = &h0000 = 0
   dwFileVersionLSh As Integer    '  e.g. = &h0031 = .31
   dwProductVersionMSl As Integer '  e.g. = &h0003 = 3
   dwProductVersionMSh As Integer '  e.g. = &h0010 = .1
   dwProductVersionLSl As Integer '  e.g. = &h0000 = 0
   dwProductVersionLSh As Integer '  e.g. = &h0031 = .31
   dwFileFlagsMask As Long        '  = &h3F for version "0.42"
   dwFileFlags As Long            '  e.g. VFF_DEBUG Or VFF_PRERELEASE
   dwFileOS As Long               '  e.g. VOS_DOS_WINDOWS16
   dwFileType As Long             '  e.g. VFT_DRIVER
   dwFileSubtype As Long          '  e.g. VFT2_DRV_KEYBOARD
   dwFileDateMS As Long           '  e.g. 0
   dwFileDateLS As Long           '  e.g. 0
End Type

This should get you the version info:
   

    Dim rc As Long
    Dim lDummy As Long
    Dim lBufferLen As Long
    Dim lVerPointer As Long
    Dim udtVerBuffer As VS_FIXEDFILEINFO
    Dim lVerbufferLen As Long
    Dim sFileVer As String
   
    '*** Get size ****
    lBufferLen = GetFileVersionInfoSize(sFullFileName, lDummy)
   
    If lBufferLen < 1 Then
        GetCarmaFileVersion = ""
        Exit Function
    End If
   
    '**** Store info to udtVerBuffer struct ****
    ReDim sBuffer(lBufferLen) As Byte
    rc = GetFileVersionInfo(sFullFileName, 0&, lBufferLen, sBuffer(0))
    rc = VerQueryValue(sBuffer(0), "\", lVerPointer, lVerbufferLen)
    MoveMemory udtVerBuffer, lVerPointer, Len(udtVerBuffer)
   
    '**** Determine File Version number ****
    sFileVer = Format$(udtVerBuffer.dwFileVersionMSh) & "." & _
       Format$(udtVerBuffer.dwFileVersionMSl) & "." & _
       Format$(udtVerBuffer.dwFileVersionLSh) & "." & _
       Format$(udtVerBuffer.dwFileVersionLSl)


Cheers,
       aswirthm
0
 
1114goddersCommented:
Yes but how do you get the values to populate sFullFileName ?????
0
All Courses

From novice to tech pro — start learning today.