[API]
GetFileVersionInfoA
GetFileVersionInfoSizeA
VerQueryValueA

[INCLUDE]
PeekS_Ansi

[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 xChar1 As String
  Dim xChar2 As String

  xChar1 = AppBase()
  xLong1 = GetFileVersionInfoSizeA(xChar1, xLong2)
  If Not xLong1 = 0& Then
    xChar2 = String(xLong1, vbNullChar)
    If Not GetFileVersionInfoA(xChar1, xLong2, xLong1, ByVal xChar2) = 0& Then
      If WantFileDescInstead Then
        If Not VerQueryValueA(ByVal xChar2, "\StringFileInfo\040904B0\FileDescription" & vbNullChar, xLong1, xLong2) = 0& Then
          xChar1 = PeekS_Ansi(xLong1)
          End If
        Else
        If Not VerQueryValueA(ByVal xChar2, "\StringFileInfo\040904B0\ProductName" & vbNullChar, xLong1, xLong2) = 0& Then
          xChar1 = PeekS_Ansi(xLong1)
          End If
        End If
      If WantFileVerInstead Then
        If Not VerQueryValueA(ByVal xChar2, "\StringFileInfo\040904B0\FileVersion" & vbNullChar, xLong1, xLong2) = 0& Then
          GetBuildNumber = PeekS_Ansi(xLong1)
          End If
        Else
        If Not VerQueryValueA(ByVal xChar2, "\StringFileInfo\040904B0\ProductVersion" & vbNullChar, xLong1, xLong2) = 0& Then
          GetBuildNumber = PeekS_Ansi(xLong1)
          End If
        End If
      If Len(GetBuildNumber) = 0& Then GetBuildNumber = "???"
      If Len(xChar1) = 0& Then xChar1 = "???"
      If ResIDDefault = -1& Then
        GetBuildNumber = xChar1 & " " & GetBuildNumber
        ElseIf Not ResIDDefault = -2& Then
        GetBuildNumber = Replace(Replace(LoadResEx_String(ResIDDefault), "$V", GetBuildNumber, , , vbTextCompare), "$P", xChar1, , , vbTextCompare)
        End If
      End If
    End If
  #If InIDE Then
    If Len(GetBuildNumber) = 0& Then GetBuildNumber = "<n/a in IDE>"
    #End If
  End Function
