Error retrieving file version information using "VerQueryValue" 
Author Message
 Error retrieving file version information using "VerQueryValue"

Dear colleague,

I'm trying to create an application launcher program (using VB 6.0 SP3) in
which I have to retrieve the version information from the executable file
the user is trying to launch.

For this I'm calling a number of Windows API functions
(GetFileVersionInfoSize, GetFileVersionInfo, VerQueryValue and MoveMemory)
as described in the Microsoft Knowlegde Base Article Q139491 (originally
written for VB 4.0).

However, at the point where VB calls the VerQueryValue function, I receive
following error message:
----------------------------------------------------------------------------
-------------
VB6.EXE - Application Error
The instruction at "0x77a9253a" referenced memory at "0x00000000".  The
memory could not be "written".
Click OK to terminate the application
Click CANCEL to debug the application
----------------------------------------------------------------------------
-------------

I checked my code over and over, but I'm not able to solve this problem.
Can anybody help me?!

Regards from Belgium,
Philippe Rubbrecht



Tue, 08 Jan 2002 03:00:00 GMT  
 Error retrieving file version information using "VerQueryValue"
Quote:

snip......
> However, at the point where VB calls the VerQueryValue function, I receive
> following error message

more snip.....

-----
Phillipe: Without seeing your code it's hard to debug it. Since it takes
more comments than code to use these functions, I'm including a working
version here that you can use to compare with your trouble code, or just use
this if it suits your needs. This code should run on all 32bit flavors of
VB.

Keep Smilin'
Ed Stegman
-------
Option Explicit
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
Private Declare Function GetFileVersionInfoSize Lib "Version.dll" Alias
"GetFileVersionInfoSizeA" _
  (ByVal lptstrFilename As String, lpdwHandle As Long) As Long
Private Declare Function VerQueryValue Lib "Version.dll" Alias
"VerQueryValueA" _
  (pBlock As Any, ByVal lpSubBlock As String, lplpBuffer As Any, puLen As
Long) As Long
Private Type VS_FIXEDFILEINFO
    dwSignature As Long
    dwStrucVersionl As Integer
    dwStrucVersionh As Integer
    dwFileVersionMSl As Integer
    dwFileVersionMSh As Integer
    dwFileVersionLSl As Integer
    dwFileVersionLSh As Integer
    dwProductVersionMSl As Integer
    dwProductVersionMSh As Integer
    dwProductVersionLSl As Integer
    dwProductVersionLSh As Integer
    dwFileFlagsMask As Long
    dwFileFlags As Long
    dwFileOS As Long
    dwFileType As Long
    dwFileSubtype As Long
    dwFileDateMS As Long
    dwFileDateLS As Long
End Type

Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _
  (dest As Any, ByVal Source As Long, ByVal length As Long)

Public Function GetFileVersion(ByVal sFilename As String) As Variant
'Returns a Variant containing a zero based Variant array with 5 elements on
success.
  'Array Elements:
    '0 to 3 contain integers that can be easily used for comparisons
      '0 - Major (..MSh) high word
      '1 - Minor (...MSl) low word
      '2 - Not used by VB (...LSh) high word
      '3 -Build (...LSl) low word
    '4 contains a formatted string for displaying the version info.
      'string format: 0.00.00
'Returns a string error message on trapped error.
  'String format: <err num>, <source>,<description>

'Usage:
''  Dim vFileInfo As Variant
''  Const FILE_INFO_STR& = 4
''  vFileInfo = GetFileVersion(txtFilePath.Text)
''  If IsArray(vFileInfo) Then 'Success !
''    txtVersion.Text = vFileInfo(FILE_INFO_STR)
''    If (vFileInfo(0) < 7) And  (vFileInfo(1) < 3) Then MsgBox "You need to
upgrade." _
''      & vbCrLf & _
''      "This version is mostly hype and should have stayed Beta for another
year."
''  Else 'failed
''    MsgBox FormatErrStr(vFileInfo)
''  End If

  Dim lRet As Long
  Dim lUseless  As Long 'hehehe This is a gem!! Maybe used by Windows5000 ?
  Dim abBuffer() As Byte
  Dim lBufferLen As Long
  Dim lpVersion As Long
  Dim tagFixedFileInfo As VS_FIXEDFILEINFO
  Dim lFixedFileInfoLen As Long
  Dim avRet(0 To 4) As Variant

  On Error GoTo EH

  ' Get the size needed for the buffer
  lBufferLen = GetFileVersionInfoSize(sFilename, lUseless)

  If lBufferLen >= 1 Then
    'Success, size the buffer
    ReDim abBuffer(lBufferLen) As Byte
    'Get the version resource
    lRet = GetFileVersionInfo(sFilename, 0&, lBufferLen, abBuffer(0))
    ' Now for some contortions that are anything but intuitive
    lRet = VerQueryValue(abBuffer(0), "\", lpVersion, lFixedFileInfoLen)
    CopyMemory tagFixedFileInfo, lpVersion, Len(tagFixedFileInfo)

    'move it into our returning array
    With tagFixedFileInfo
      avRet(0) = .dwFileVersionMSh 'Major
      avRet(1) = .dwFileVersionMSl 'Minor
      avRet(2) = .dwFileVersionLSh 'NOTE: Not used by VB.
      avRet(3) = .dwProductVersionLSl 'Build #

      'format as 0.00.0000
      avRet(4) = Format$(.dwFileVersionMSh, "0") & "." & _
        Format$(.dwFileVersionMSl, "00") & "." & _
        Format$(.dwFileVersionLSl, "00")
        ' NOTE: VB doesn't put anything here >>>> .dwFileVersionLSh
    End With
    GetFileVersion = avRet()
  Else 'failed
    GetFileVersion = "ERR_FAILED_GET_VERSION, GetFileVersion, Failed to find
version info for " & sFilename
  End If

ExitNow:
  Err.Clear
  Exit Function

EH:
  GetFileVersion = Err.Number & "," & "GetFileVersion:=>" & Err.Source & ","
& Err.Description
  Resume ExitNow

End Function



Tue, 08 Jan 2002 03:00:00 GMT  
 Error retrieving file version information using "VerQueryValue"


Fri, 19 Jun 1992 00:00:00 GMT  
 Error retrieving file version information using "VerQueryValue"
Dear Ed,

Thank you for your code... it works fine !!
It resembles mine for about 99%, so the errors must have been in some small
part of the API function declarations.

I'm not gonna search any longer for more differences, thanks again !!!

Best regards, Philippe



Fri, 11 Jan 2002 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. VerQueryValue API - getting a files version information

2. Invalid "wrong NT Version" error

3. "Error loading from file" error message

4. Retrieving File Version information in VB

5. "Unknown error" using GetFolderFromID method

6. "Unknown error" using GetFolderFromID method

7. "Not Liscensed" error using Sheridan 3dcontrols

8. VB--- error using GetObjectContext.Item("Request")

9. VB6--- error using GetObjectContext.Item("Request")

10. Using different sound file for "beep"

11. Using the common dialog "Open file"

12. Using a standard "File open" dialog

 

 
Powered by phpBB® Forum Software