[API]
GetFileVersionInfoA
GetFileVersionInfoW
GetFileVersionInfoSizeA
GetFileVersionInfoSizeW

[INCLUDE]
VerQueryValue

[CODE]
Public Function GetBuildNumber(Optional ByVal ResIDDefault As Long = -1&, Optional ByVal WantFileDescInstead As Boolean = False, Optional ByVal WantFileVerInstead As Boolean) As String
  Dim xLong1 As Long
  Dim xLong2 As Long
  Dim hMem As Long
  Dim xChar1 As String
  Dim xChar2 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
        If WantFileDescInstead Then
          xChar2 = VerQueryValue(hMem, "\StringFileInfo\040904B0\FileDescription")
          Else
          xChar2 = VerQueryValue(hMem, "\StringFileInfo\040904B0\ProductName")
          End If
        If WantFileVerInstead Then
          GetBuildNumber = VerQueryValue(hMem, "\StringFileInfo\040904B0\FileVersion")
          Else
          GetBuildNumber = VerQueryValue(hMem, "\StringFileInfo\040904B0\ProductVersion")
          End If
        If Len(GetBuildNumber) = 0& Then GetBuildNumber = "???"
        If Len(xChar2) = 0& Then xChar2 = "???"
        If ResIDDefault = -1& Then
          GetBuildNumber = xChar2 & " " & GetBuildNumber
  #If LoadResEx_String Then
          ElseIf Not ResIDDefault = -2& Then
          GetBuildNumber = Replace(Replace(LoadResEx_String(ResIDDefault), "$V", GetBuildNumber, , , vbTextCompare), "$P", xChar2, , , vbTextCompare)
  #End If
          End If
        End If
      Call LocalFree(hMem)
      End If
    End If
  #If InIDE Then
    If Len(GetBuildNumber) = 0& Then GetBuildNumber = "<n/a in IDE>"
    #End If
  End Function
