[API]
GetFileVersionInfoA
GetFileVersionInfoW
GetFileVersionInfoSizeA
GetFileVersionInfoSizeW
VerQueryValueA
VerQueryValueW

[DEFINE]
Public Enum GetFileVersionField_Enum
  GetFileVersionField_Comments
  GetFileVersionField_CompanyName
  GetFileVersionField_FileDesc
  GetFileVersionField_FileVersion
  GetFileVersionField_InternalName
  GetFileVersionField_LegalCopyright
  GetFileVersionField_LegalTrademarks
  GetFileVersionField_OriginalFilename
  GetFileVersionField_PrivateBuild
  GetFileVersionField_ProductName
  GetFileVersionField_ProductVersion
  GetFileVersionField_SpecialBuild
  End Enum

[CODE]
Public Function GetFileVersionField(ByVal FieldType As GetFileVersionField_Enum, Optional ByVal DefaultValue As String = "???") As String
  Dim xLong1 As Long
  Dim xLong2 As Long
  Dim hMem As Long
  Dim xChar1 As String
  Dim FieldStr As String

  xChar1 = AppBase()
  If IsUnicode Then
    xLong1 = GetFileVersionInfoSizeW(StrPtr(xChar1), xLong2)
    Else
    xLong1 = GetFileVersionInfoSizeA(xChar1, xLong2)
    End If
  If Not xLong1 = 0& Then
    hMem = LocalAlloc(&H40&, xLong1)
    If Not hMem = 0& Then
      If IsUnicode Then
        xLong1 = GetFileVersionInfoW(StrPtr(xChar1), xLong2, xLong1, ByVal hMem)
        Else
        xLong1 = GetFileVersionInfoA(xChar1, xLong2, xLong1, ByVal hMem)
        End If
      If Not xLong1 = 0& Then
        'xChar1 = VerQueryValue(hMem, CStr(FieldType))
        Select Case FieldType
          Case GetFileVersionField_Comments:         FieldStr = "Comments"
          Case GetFileVersionField_CompanyName:      FieldStr = "CompanyName"
          Case GetFileVersionField_FileDesc:         FieldStr = "FileDescription"
          Case GetFileVersionField_FileVersion:      FieldStr = "FileVersion"
          Case GetFileVersionField_InternalName:     FieldStr = "InternalName"
          Case GetFileVersionField_LegalCopyright:   FieldStr = "LegalCopyright"
          Case GetFileVersionField_LegalTrademarks:  FieldStr = "LegalTrademarks"
          Case GetFileVersionField_OriginalFilename: FieldStr = "OriginalFilename"
          Case GetFileVersionField_PrivateBuild:     FieldStr = "PrivateBuild"
          Case GetFileVersionField_ProductName:      FieldStr = "ProductName"
          Case GetFileVersionField_ProductVersion:   FieldStr = "ProductVersion"
          Case GetFileVersionField_SpecialBuild:     FieldStr = "SpecialBuild"
          Case Else: GoTo IncompatibleFieldType
          End Select
        FieldStr = "\StringFileInfo\040904B0\" + FieldStr + vbNullChar
        If IsUnicode Then
          If Not VerQueryValueW(ByVal hMem, StrPtr(FieldStr), xLong1, xLong2) = 0& Then
            #If PeekS_Wide Then
              GetFileVersionField = PeekS_Wide(xLong1, xLong2)
              #Else
              GoTo PeekShared
              #End If
            End If
          ElseIf Not VerQueryValueA(ByVal hMem, FieldStr, xLong1, xLong2) = 0& Then
          #If PeekS_Ansi Then
            GetFileVersionField = PeekS_Ansi(xLong1, xLong2)
            #Else
PeekShared:
            GetFileVersionField = PeekS(xLong1, xLong2)
            #End If
          End If
IncompatibleFieldType:
        End If
      Call LocalFree(hMem)
      End If
    End If
  #If InIDE Then
    If Len(GetFileVersionField) = 0& Then GetFileVersionField = "<n/a in IDE>"
    #Else
    If Len(GetFileVersionField) = 0& Then GetFileVersionField = DefaultValue
    #End If
  End Function
