Results 1 to 4 of 4

Thread: Retrieving a DLL file's version information

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2001
    Posts
    2

    How do I retrieve the version information of a DLL file into my program?

  2. #2
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    Use the GetFileVersionInfo API.
    I am become death, the destroyer of worlds.
    mail:[email protected]

    • Visual Basic 6.0 & .NET
    • Visual C++ 6.0 & .NET
    • ASP
    • LISP
    • PROLOG
    • C
    • Pascal

  3. #3
    Guest
    Here is an example:

    Code:
    'Author: Riaan Aspeling
    'Origin: http://www.planet-source-code.com
    'Purpose: GetFileVersion
    'Version: VB5+ 
    
    Private 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
    
    
    Private Declare Function GetFileVersionInfoSize Lib "Version.dll" Alias "GetFileVersionInfoSizeA" (ByVal lptstrFilename As String, lpdwHandle As Long) As Long
    
    
    Private Declare Function VerQueryValue Lib "Version.dll" Alias "VerQueryValueA" (pBlock As Any, ByVal lpSubBlock As String, lplpBuffer As Any, puLen As Long) As Long
    
    
    Private Declare Sub MoveMemory Lib "kernel32" Alias "RtlMoveMemory" (dest As Any, ByVal Source As Long, ByVal Length As Long)
    
    
    Private 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
    
    'Example to use this function
    'MsgBox " Notepad's Version is " & Check
    '     FileVersion("C:\Windows\Notepad.exe")
    
    
    Private Function CheckFileVersion(FilenameAndPath As Variant) As Variant
        On Error Goto HandelCheckFileVersionError
        Dim lDummy As Long, lsize As Long, rc As Long
        Dim lVerbufferLen As Long, lVerPointer As Long
        Dim sBuffer() As Byte
        Dim udtVerBuffer As VS_FIXEDFILEINFO
        Dim ProdVer As String
        lsize = GetFileVersionInfoSize(FilenameAndPath, lDummy)
        If lsize < 1 Then Exit Function
        ReDim sBuffer(lsize)
        rc = GetFileVersionInfo(FilenameAndPath, 0&, lsize, sBuffer(0))
        rc = VerQueryValue(sBuffer(0), "\", lVerPointer, lVerbufferLen)
        MoveMemory udtVerBuffer, lVerPointer, Len(udtVerBuffer)
        '**** Determine Product Version number *
        '     ***
        ProdVer = Format$(udtVerBuffer.dwProductVersionMSh) & "." & Format$(udtVerBuffer.dwProductVersionMSl)
        'Full number:
        'ProdVer = Format$(udtVerBuffer.dwProductVersionMSh) & "." & Format$(udtVerBuffer.dwProductVersionMSl) & "." & Format$(udtVerBuffer.dwFileVersionLSh) & Format$(udtVerBuffer.dwFileVersionLSl)
        CheckFileVersion = ProdVer
        Exit Function
        HandelCheckFileVersionError:
        CheckFileVersion = "N/A"
        Exit Function
    End Function

  4. #4

    Thread Starter
    New Member
    Join Date
    Jan 2001
    Posts
    2

    Thank you, that worked nicely!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width