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

x
?
Solved

(100 pts) GetFileVersionInfo API Problem

Posted on 1999-07-23
2
Medium Priority
?
350 Views
Last Modified: 2006-11-17
Hello,

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.
Registers:
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
 
  TheFile = "C:\WINDOWS\EXPLORER.EXE"
 
  ' 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
 
ErrorTrap:
 
  If Err.Number = 0 Then ' No Error
    Resume Next
  ElseIf Err.Number = 20 Then ' Resume Without Error
    Resume Next
  Else
    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
    Err.Clear
    Exit Sub
  End If
 
End Sub
0
Comment
Question by:HATCHET1
[X]
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
2 Comments
 

Accepted Solution

by:
dlawlis earned 400 total points
ID: 1527031

http://www.mvps.org/vb/
Download: FileInfo.zip

Nice Class module to do what you want.
0
 

Author Comment

by:HATCHET1
ID: 1527032
dlawlis,

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

http://www.mvps.org/vb/code/FileInfo.zip

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

HATCHET
0

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