vb400
Jan 4th, 2001, 06:08 PM
How do I retrieve the version information of a DLL file into my program?
Vlatko
Jan 4th, 2001, 08:24 PM
Use the GetFileVersionInfo API.
Here is an example:
'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
vb400
Jan 5th, 2001, 09:20 AM
Thank you, that worked nicely!