Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools

GetFileVersionData - Retrieve file versioning information

Total Hit ( 2261)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article

Rating


 



Click here to copy the following block
Private Declare Function GetFileVersionInfoSize Lib "version.dll" Alias _
  "GetFileVersionInfoSizeA" (ByVal lptstrFilename As String, _
  lpdwHandle As Long) As Long
Private Declare Function GetFileVersionInfo Lib "version.dll" Alias _
  "GetFileVersionInfoA" (ByVal lptstrFilename As String, _
  ByVal dwHandle As Long, ByVal dwLen As Long, lpData As Any) As Long

' Get versioning information about a file
' it only works with Win32 files, and under Windows 95/98 the short path
' form of the specified file name must be less than 126 characters.
'
' If unsuccessful returns Empty
' If successful returns an array of strings in the format
'    "resourcename: resourcevalue"
' if a resource value hasn't been found, the string contains
' just the resource name, and you can filter out these items
' using the following statement
'   resources() = Filter(GetFileVersionData(FileName), ":")
'
' Usage:
'   Dim res As Variant, i As Long
'   res = GetFileVersionData(FileName)
'   If IsArray(res) Then
'     For i = LBound(res) To UBound(res)
'       Debug.Print res(i)
'     Next
'   End If

Function GetFileVersionData(ByVal FileName As String) As Variant
  Dim length As Long
  Dim handle As Long
  Dim buffer As String
  Dim index As Long
  Dim pos As Long
  
  ' get the size of the version info block
  ' (handle is always set to zero by the function
  length = GetFileVersionInfoSize(FileName, handle)
  If length = 0 Then Exit Function
  
  ' create the buffer (these are Unicode chars)
  buffer = Space$(length)
  
  ' get version information (2nd argument is ignored)
  If GetFileVersionInfo(FileName, handle, length, ByVal StrPtr(buffer)) = 0 _
    Then
    ' a zero return value means error
    Exit Function
  End If
  
  ' extract version information out of the buffer
  ' IMPORTANT: it doesn't use the official APIs, instead
  ' it uses euristics to extract the strings, and might
  ' fail under some circumstances
  
  ' create an array with the names of all the standard resources
  Dim res() As String
  res() = Split("CompanyName;FileDescription;FileVersion;InternalName;" & _
    "LegalCopyright;OriginalFilename;ProductName;ProductVersion;" & _
    "Comments;LegalTrademarks;PrivateBuild;SpecialBuild", ";")
  
  ' repeat for all the standard resources
  For index = 0 To UBound(res)
    pos = InStr(buffer, res(index))
    If pos Then
      ' skip over the resource name
      pos = pos + Len(res(index)) + 1
      ' if this is a null char, skip over it
      If Mid$(buffer, pos, 1) = vbNullChar Then pos = pos + 1
      
      ' extract the null terminated string and
      ' append it to the resource name
      res(index) = res(index) & ": " & Mid$(buffer, pos, InStr(pos, _
        buffer, vbNullChar) - pos)
    End If
  Next
  
  GetFileVersionData = res()
  
End Function


Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.