Declare Function GetFileVersionInfoSize Lib "ver.dll" (ByVal lpszFileName As String, lpdwHandle As Long) As Long
Declare Function GetFileVersionInfo Lib "ver.dll" (ByVal lpszFileName As String, ByVal lpdwHandle As Long, ByVal cbbuf As Long, ByVal lpvdata As String) As Integer
Declare Function VerQueryValue Lib "ver.dll" (ByVal lpvBlock As String, ByVal lpszSubBlock As String, lplpBuffer As Long, lpcb As Integer) As Integer
Declare Function VerLanguageName Lib "ver.dll" (ByVal LangID As Integer, ByVal LangName As String, ByVal LangLen As Integer) As Integer
Declare Function lstrcpyn Lib "Kernel" (ByVal lpszString1 As Any, ByVal lpszString2 As Long, ByVal cChars As Integer) As Long
Declare Function WritePrivateProfileString Lib "Kernel" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpString As String, ByVal lplFileName As String) As Integer
Declare Function GetPrivateProfileString Lib "Kernel" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Integer, ByVal lpFileName As String) As Integer
Declare Function GetPrivateProfileInt Lib "Kernel" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal nDefault As Integer, ByVal lpFileName As String) As Integer
Type VerInfo
FileVersion As String
FileDescription As String
CompanyName As String
Language As String
Comments As String
OriginalFileName As String
InternalName As String
LegalCopyright As String
LegalTrademarks As String
ProductName As String
ProductVersion As String
SpecialBuild As String
PrivateBuild As String
End Type
Global DispTop As Integer
Global DispLeft As Integer
Global PrintTop As Integer
Global PrintLeft As Integer
Dim ResName(16) As String
Dim ResValue(16) As String
Function GetFileVersion (FileToCheck As String, VI As VerInfo) As Integer
Dim VersionInfoSize As Long ' size of Version Resource
Dim Handle As Long ' Handle to Version Resource
Dim VerRes As String ' Version resource, retrieved from File
Dim Value As String ' String returned by API call
Dim ValueLen As Integer ' Length of String returned by API call (Value)
Dim Pointer As Long ' 32-bit address of string returned by API call
Dim Result As Integer ' 16-bit value returned by API call
Dim lResult As Long ' 32-bit value returned by API call
Dim Translation As String ' Language/Charset value, in hex
' Reset Version info
VI.FileVersion = ""
VI.FileDescription = ""
VI.CompanyName = ""
VI.Language = ""
VI.OriginalFileName = ""
VI.InternalName = ""
VI.Comments = ""
VI.LegalCopyright = ""
VI.LegalTrademarks = ""
VI.ProductName = ""
VI.ProductVersion = ""
VI.SpecialBuild = ""
VI.PrivateBuild = ""
On Error Resume Next
VersionInfoSize = GetFileVersionInfoSize(FileToCheck, Handle) ' How big is the V/R?
If VersionInfoSize = 0 Then ' No Version Resource present :(
GetFileVersion = False
Exit Function
End If
VerRes = String$(VersionInfoSize, Chr$(0))
Result = GetFileVersionInfo(FileToCheck, Handle, VersionInfoSize, VerRes) ' get copy of V/R
Result = VerQueryValue(VerRes, "\VarFileInfo\Translation", Pointer, ValueLen) ' Get translation info
If ValueLen = 4 Then ' Looks like we've got a valid translation info
Value = String$(ValueLen + 1, Chr$(0))
lResult = lstrcpyn(Value, Pointer, ValueLen + 1)
Translation = ToHex(Left$(Value, 4)) ' trim the trailing null, and convert to hex
GoTo GetValues ' Let's start extracting version info!
Else ' apparently the Translation info is not there, let's try guessing ...