Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


(100 pts) GetFileVersionInfo API Problem

Posted on 1999-07-23
Medium Priority
Last Modified: 2006-11-17

I'm trying to write some code to get the "File Description" of a specified file.  It's a lot harder than I thought and I'm having problems.  When I run the code I wrote, I get the following Error and VB crashes when it hits the "GetFileVersionInfo" function.  What am I doing wrong?

VB5 caused an invalid page fault in
module <unknown> at 0000:28544e20.
EAX=81745970 CS=0137 EIP=28544e20 EFLGS=00010246
EBX=007ff2c0 SS=013f ESP=007000b0 EBP=007000d0
ECX=00700158 DS=013f ESI=0070019c FS=420f
EDX=bff7678c ES=013f EDI=00700180 GS=0000
Bytes at CS:EIP:

Stack dump:
bff76780 00700180 007ff2c0 0070019c 00700158 0070028c bff7678c 007ff2c0 00700168 bff858f3 00700180 007ff2c0 0070019c 00700158 28544e20 00700348


Here's the code I have in a form that's started by Command1_Click:

Option Explicit

Private Declare Function VerQueryValue Lib "version.dll" (pBlock As Any, ByVal lpSubBlock As String, ByVal lplpBuffer As Long, puLen As Long) As Long
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
Private Declare Function GetLastError Lib "kernel32" () As Long

Private Sub Command1_Click()
On Error GoTo ErrorTrap

  Dim FileInfoSize As Long
  Dim FileInfo As Long
  Dim ErrorNumber As Long
  Dim TheHandle As Long
  Dim TheFile As String
  Dim TheFileInfo As String
  Dim VersionInfo As String
  Dim BufferPointer As Long
  Dim InfoLength As Long
  ' Get File Size
  FileInfoSize = GetFileVersionInfoSize(TheFile, 0)
  If FileInfoSize = 0 Then
    ErrorNumber = GetLastError
    MsgBox "An error occured in GetFileVersionInfoSize :" & Chr(13) & Chr(13) & "  Error Number : " & CStr(ErrorNumber), vbOKOnly + vbExclamation, "  Error Occured"
    Exit Sub
  End If
  ' Get File Information  (Here's where it crashes)
  FileInfo = GetFileVersionInfo(TheFile, 0, FileInfoSize, TheFileInfo)
  If FileInfo = 0 Then
    ErrorNumber = GetLastError
    MsgBox "An error occured in GetFileVersionInfo :" & Chr(13) & Chr(13) & "  Error Number : " & CStr(ErrorNumber), vbOKOnly + vbExclamation, "  Error Occured"
    Exit Sub
  End If
  ' Get File Version Info
  VersionInfo = VerQueryValue(TheFileInfo, "\StringFileInfo\040904E4\FileDescription", BufferPointer, InfoLength)
  If FileInfo = 0 Then
    ErrorNumber = GetLastError
    MsgBox "An error occured in VerQueryValue :" & Chr(13) & Chr(13) & "  Error Number : " & CStr(ErrorNumber), vbOKOnly + vbExclamation, "  Error Occured"
    Exit Sub
  End If
  Exit Sub
  If Err.Number = 0 Then ' No Error
    Resume Next
  ElseIf Err.Number = 20 Then ' Resume Without Error
    Resume Next
    MsgBox Err.Source & " caused the following error while trying to get the file information:" & Chr(13) & Chr(13) & "Error Number : " & CStr(Err.Number) & Chr(13) & "Error Description : " & Err.Description, vbOKOnly + vbExclamation, "  Error  -  " & Err.Description
    Exit Sub
  End If
End Sub
Question by:HATCHET1
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Accepted Solution

dlawlis earned 400 total points
ID: 1527031

Nice Class module to do what you want.

Author Comment

ID: 1527032

I downloaded and checked out the following file like you recommended :

EXCELLENT EXAMPLE !!!  Very, very well done.  I'm very impressed.  It does what I need and more !!  Thank you for pointing me to it.


Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

660 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question