473,323 Members | 1,589 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,323 software developers and data experts.

Crashing getfileversioninfo function, what did I do wrong ?

Below is a code part I got somewhere and works fine for retrieving a
version from a single file. Now I want to retrieve all .dll, .ocx and
..exe file versions from my harddisk in all directory's. I generate a
array of all those files and then in a loop request the version for
each of those files.

Now it randomly crashes with a error that it cannot write to memory at
location xxxxxx. I cannot find the error and adding 'on error goto
blabla' doesnt help at all. Whats wrong on the code below ?

Many thanks for looking at it,
Fabster
Option Explicit

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
Declare Function GetFileVersionInfoSize Lib "Version.dll" Alias
"GetFileVersionInfoSizeA" (ByVal lptstrFilename As String, lpdwHandle
As Long) As Long
Declare Function VerQueryValue Lib "Version.dll" Alias
"VerQueryValueA" (pBlock As Any, ByVal lpSubBlock As String,
lplpBuffer As Any, puLen As Long) As Long
Declare Sub MoveMemory Lib "kernel32" Alias "RtlMoveMemory" (dest As
Any, ByVal Source As Long, ByVal Length As Long)
Declare Function lstrcpy Lib "kernel32" Alias "lstrcpyA" (ByVal
lpString1 As String, ByVal lpString2 As Long) As Long

Public Type FILEPROPERTIE
CompanyName As String
FileDescription As String
FileVersion As String
InternalName As String
LegalCopyright As String
OrigionalFileName As String
ProductName As String
ProductVersion As String
End Type

Public Function fileinfo(Optional ByVal PathWithFilename As String) As
FILEPROPERTIE
Dim lngBufferlen As Long
Dim lngDummy As Long
Dim lngRc As Long
Dim lngVerPointer As Long
Dim lngHexNumber As Long
Dim bytBuffer() As Byte
Dim bytBuff(255) As Byte
Dim strBuffer As String
Dim strLangCharset As String
Dim strVersionInfo(7) As String
Dim strTemp As String
Dim intTemp As Integer

On Error GoTo 0
' size
lngBufferlen = GetFileVersionInfoSize(PathWithFilename, lngDummy)
If lngBufferlen > 0 Then
ReDim bytBuffer(lngBufferlen)
lngRc = GetFileVersionInfo(PathWithFilename, 0&, lngBufferlen,
bytBuffer(0))
If lngRc <> 0 Then
lngRc = VerQueryValue(bytBuffer(0),
"\VarFileInfo\Translation", lngVerPointer, lngBufferlen)
If lngRc <> 0 Then
'lngVerPointer is a pointer to four 4 bytes of Hex number,
'first two bytes are language id, and last two bytes are
code
'page. However, strLangCharset needs a string of
'4 hex digits, the first two characters correspond to the
'language id and last two the last two character correspond
'to the code page id.
MoveMemory bytBuff(0), lngVerPointer, lngBufferlen
lngHexNumber = bytBuff(2) + bytBuff(3) * &H100 + bytBuff(0)
* &H10000 + bytBuff(1) * &H1000000
strLangCharset = Hex(lngHexNumber)
'now we change the order of the language id and code page
'and convert it into a string representation.
'For example, it may look like 040904E4
'Or to pull it all apart:
'04------ = SUBLANG_ENGLISH_USA
'--09---- = LANG_ENGLISH
' ----04E4 = 1252 = Codepage for Windows:Multilingual
Do While Len(strLangCharset) < 8
strLangCharset = "0" & strLangCharset
Loop
' assign propertienames
strVersionInfo(0) = "CompanyName"
strVersionInfo(1) = "FileDescription"
strVersionInfo(2) = "FileVersion"
strVersionInfo(3) = "InternalName"
strVersionInfo(4) = "LegalCopyright"
strVersionInfo(5) = "OriginalFileName"
strVersionInfo(6) = "ProductName"
strVersionInfo(7) = "ProductVersion"
' loop and get fileproperties
For intTemp = 0 To 7
strBuffer = String$(255, 0)
strTemp = "\StringFileInfo\" & strLangCharset & "\" &
strVersionInfo(intTemp)
lngRc = VerQueryValue(bytBuffer(0), strTemp,
lngVerPointer, lngBufferlen)
If lngRc <> 0 Then
' get and format data
lstrcpy strBuffer, lngVerPointer
strBuffer = Mid$(strBuffer, 1, InStr(strBuffer, Chr(0))
- 1)
strVersionInfo(intTemp) = strBuffer
Else
' property not found
strVersionInfo(intTemp) = "?"
End If
Next intTemp
End If
End If
End If
' assign array to user-defined-type
fileinfo.CompanyName = strVersionInfo(0)
fileinfo.FileDescription = strVersionInfo(1)
fileinfo.FileVersion = strVersionInfo(2)
fileinfo.InternalName = strVersionInfo(3)
fileinfo.LegalCopyright = strVersionInfo(4)
fileinfo.OrigionalFileName = strVersionInfo(5)
fileinfo.ProductName = strVersionInfo(6)
fileinfo.ProductVersion = strVersionInfo(7)
End Function
Jul 17 '05 #1
0 3777

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: xytho33 | last post by:
I need to be able to programatically get the version info from a windows DLL preferably in the same format as what is displayed in the properties tab. I was overjoyed to find Mark Hammond's...
2
by: xytho33 | last post by:
I need to be able to programatically get the version info from a windows DLL preferably in the same format as what is displayed in the properties tab. I was overjoyed to find Mark Hammond's...
2
by: L. Shestov | last post by:
I need to be able to programatically get the version info from a windows DLL preferably in the same format as what is displayed in the properties tab. I was overjoyed to find Mark Hammond's...
0
by: Henry Hank | last post by:
Environment: I'm setting up a database server on a Dell Poweredge 2650, dual 1.8GHZ pentium with 1GB of memory and RAID5 drives. I've installed RedHat 9, and updated the kernel to 2.4.20-19.9smp....
5
by: Eddie | last post by:
I have a MySQL-server running Innodb. We have installed ~ 2GB of memory in the server. In spite of this MySQL keeps crashing due to out-of-memory errors. The server is a dual xeon i686 running...
14
by: Java and Swing | last post by:
static PyObject *wrap_doStuff(PyObject *self, PyObject *args) { // this will store the result in a Python object PyObject *finalResult; // get arguments from Python char *result = 0; char *in=...
34
by: richard | last post by:
What might cause qsort to crash? I'm using qsort to sort a few thousand items of a not too complex structure. Tried it with one data set - worked fine. Tried another similarly sized data set...
3
by: Shawn August | last post by:
Hello: I am converting a working VB6 program to C#. During testing of the C# version, I noticed the ReadFile API is crashing. The parameters going into the this function are identical to the...
2
by: =?Utf-8?B?QW5uZXh4eHh4eHg=?= | last post by:
My computer keeps crashing. The files created when it does this are: WERdc15.dir00\Mini090708-03.dmp WERdc15.dir00\sysdata.xml has anybody any idea of what these files are and the solution to...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.