Announcement

Collapse

Forum Guidelines

This forum is for finished source code that is working properly. If you have questions about this or any other source code, please post it in one of the Discussion Forums, not here.
See more
See less

Access Version Resource Strings

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • PBWin/PBCC Access Version Resource Strings

    Code:
    '------------------------------------------------------------------------------
    ' Returns version string info from a file. If sItem="", returns version number
    ' With sincere thanks to Egbert Zijlema for working it all out!
    '
    ' Updated 17th September 2002 - Fully tested OK with WinME and NT 4.0.
    '------------------------------------------------------------------------------
    Function GetVersionInfo(ByVal sFile As String, ByVal sItem As String) As String
      Local pLang As Long Ptr, sLangID As String, fvTail As String, pvTail As String, sBuf As String
      Local bSize As Long, pValue As Asciiz Ptr, dwDummy As Dword, ffi As VS_FIXEDFILEINFO Ptr
    
      ' Obtain the version block
      bSize = GetFileVersionInfoSize(ByCopy sFile, dwDummy)
      If IsFalse bSize Then Exit Function
      sBuf = Space$(bSize)
      If IsFalse GetFileVersionInfo(ByCopy sFile, 0, bSize, ByVal StrPtr(sBuf)) Then Exit Function
    
      ' If string item was specified, attempt to obtain it
      If Len(sItem) Then
         ' Check language id - default to American English if not found
         If IsFalse VerQueryValue(ByVal StrPtr(sBuf), "\VarFileInfo\Translation", pLang, dwDummy) Then
            sLangID = "040904E4" ' American English/ANSI
         Else
            sLangID = Hex$(LoWrd(@pLang), 4) + Hex$(HiWrd(@pLang), 4)
         End If
         ' Get the string information from the resource and return it
         If VerQueryValue(ByVal StrPtr(sBuf), "\StringFileInfo\" + sLangID + "\" + sItem, pValue, dwDummy) Then Function = @pValue
      Else
         ' Otherwise, query the numeric version value
         If VerQueryValue(ByVal StrPtr(sBuf), "\", ByVal VarPtr(ffi), dwDummy) Then
            fvTail = Format$(LoWrd(@ffi.dwFileVersionLS), "00")
            pvTail = Format$(LoWrd(@ffi.dwProductVersionLS), "00")
            If HiWrd(@ffi.dwFileversionLS) Then fvTail = Format$(HiWrd(@ffi.dwFileVersionLS), "00") + fvTail
            If HiWrd(@ffi.dwProductVersionLS) Then pvTail = Format$(HiWrd(@ffi.dwProductVersionLS), "00") + pvTail
            Function = Format$(HiWrd(@ffi.dwFileVersionMS)) + "." + Format$(LoWrd(@ffi.dwFileVersionMS), "00") + "." + fvTail
         End If
      End If
    End Function
    ------------------
    Kev Peel
    KGP Software
    Bridgwater, UK.
    mailto:[email protected][email protected]</A>

    [This message has been edited by K Peel (edited September 17, 2002).]

  • #2
    Code:
    '------------------------------------------------------------------------------
    ' Quick Example of GetVersionInfo function..
    '
    ' By Kev Peel, 2002. ([email protected])
    '------------------------------------------------------------------------------
    
    #Compile Exe
    #Dim All
    
    #Include "WIN32API.INC"     ' Win32API
    #Include "VERINFO.INC"      ' GetVersionInfo function
    
    
    Declare CallBack Function lbSelect
    Declare Sub UpdateDisplay
    
    Global ghMain As Dword
    
    '------------------------------------------------------------------------------
    ' Program start point
    '------------------------------------------------------------------------------
    Function PbMain
      Local szSysDir As Asciiz * %MAX_PATH
    
      Dialog New 0, "System File Inspector",,,270, 220, %WS_DLGFRAME Or %WS_CAPTION Or %WS_SYSMENU To ghMain
    
      ' Create the user interface
      Control Add Label, ghMain, -1, "GetVersionInfo Test Program by Kev Peel ([email protected])", 10, 7, 260, 10
      Control Add ListBox, ghMain, 100, ,10,20,250,110 Call lbSelect
      Control Add TextBox, ghMain, 200, "",10,130,250,80, %ES_AUTOVSCROLL Or %WS_VSCROLL Or _
      %WS_CHILD Or %WS_TABSTOP Or %WS_VISIBLE Or %ES_MULTILINE Or %ES_READONLY, %WS_EX_CLIENTEDGE
    
      ' Populate the listbox with file names
      GetSystemDirectory szSysDir, SizeOf(szSysDir)
      szSysDir = RTrim$(szSysdir, Any "/\") + "\*.DLL"
      Control Send ghMain, 100, %LB_DIR, 0, VarPtr(szSysDir)
    
      szSysDir = "kernel32.dll"
      Control Send ghMain, 100, %LB_SELECTSTRING, -1, VarPtr(szSysDir)
      UpdateDisplay
    
      Dialog Show Modal ghMain
    End Function
    
    '------------------------------------------------------------------------------
    ' Update display when user changes the list-box selection
    '------------------------------------------------------------------------------
    CallBack Function lbSelect
      If (CbMsg = %WM_COMMAND) And (CbCtlMsg = %LBN_SELCHANGE) Then
         UpdateDisplay
         Function = %True
      End If
    End Function
    
    '------------------------------------------------------------------------------
    ' Display currently selected file version info in text box
    '------------------------------------------------------------------------------
    Sub UpdateDisplay
      Local szSysDir As Asciiz * %MAX_PATH, szFile As Asciiz * %MAX_PATH, iIndex As Long, sVerInfo As String
    
      ' Get currently selected file
      Control Send ghMain, 100, %LB_GETCURSEL, 0, 0 To iIndex
      Control Send ghMain, 100, %LB_GETTEXT, iIndex, VarPtr(szFile)
    
      If Len(szFile) Then
         GetSystemDirectory szSysDir, SizeOf(szSysDir)
         szFile = RTrim$(szSysdir, Any "/\") + "\" + szFile
         ' Obtain version info and display in text box
         sVerInfo = GetVersionInfo(szFile, "CompanyName")
         If Len(sVerInfo) = 0 Then
            ' If company name was not found then display the following...
            sVerInfo = "No version information could be found!"
         Else
            ' If a version string is not found, a blank line is displayed...
            sVerInfo = sVerInfo + $CrLf + _
            GetVersionInfo(szFile, "FileDescription") + $CrLf + _
            GetVersionInfo(szFile, "FileVersion") + $CrLf + _
            GetVersionInfo(szFile, "InternalName") + $CrLf + _
            GetVersionInfo(szFile, "LegalCopyright") + $CrLf + _
            GetVersionInfo(szFile, "OriginalFilename") + $CrLf + _
            GetVersionInfo(szFile, "ProductName") + $CrLf + _
            GetVersionInfo(szFile, "ProductVersion") + $CrLf + _
            GetVersionInfo(szFile, "Comments")
         End If
         Control Set Text ghMain, 200, sVerInfo
      End If
    End Sub
    ------------------
    Kev Peel
    KGP Software, UK.
    mailto:[email protected][email protected]</A>
    kgpsoftware.com | Slam DBMS | PrpT Control | Other Downloads | Contact Me

    Comment

    Working...
    X