Attribute VB_Name = "VersionChecker"
Option Explicit

Private Declare Function GetFileVersionInfoSize Lib "version.dll" Alias "GetFileVersionInfoSizeA" _
    (ByVal Filename As String, Handle As Long) As Long
Private Declare Function GetFileVersionInfo Lib "version.dll" Alias "GetFileVersionInfoA" _
    (ByVal Filename As String, ByVal Handle As Long, ByVal Length As Long, Data As Byte) As Long
Private Declare Function VerQueryValue Lib "version.dll" Alias "VerQueryValueA" _
    (Data As Byte, ByVal Block As String, Info As Any, Length 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
    Signature As Long
    StrucVersion As Long
    FileVersionMS As Long
    FileVersionLS As Long
    ProductVersionMS As Long
    ProductVersionLS As Long
    FileFlagsMask As Long
    FileFlags As Long
    FileOS As Long
    FileType As Long
    FileSubtype As Long
    FileDateMS As Long
    FileDateLS As Long
End Type

Public Function GetMyriadAppRevision(ByVal Path As String) As Long
    Dim Buf() As Byte
    Dim Info As VS_FIXEDFILEINFO
    Dim Handle As Long
    Dim Address As Long
    Dim VerLength As Long
    Dim Length As Long
    
    GetMyriadAppRevision = -1
    
    VerLength = GetFileVersionInfoSize(Path, Handle)
    If (VerLength = 0) Then _
        Exit Function
    ReDim Buf(VerLength) As Byte
    
    If (GetFileVersionInfo(Path, Handle, VerLength, Buf(0)) = 0) Then _
        Exit Function
    
    If (VerQueryValue(Buf(0), "\", Address, Length) = 0) Then _
        Exit Function
    
    MoveMemory Info, Address, 52
    
    GetMyriadAppRevision = (Info.FileVersionLS And &HFFFF)
End Function
