Skip to content

Commit bc163fd

Browse files
committed
healed creating buffer in New_, and converting unsigned int16 to int32
1 parent a6751eb commit bc163fd

3 files changed

Lines changed: 33 additions & 25 deletions

File tree

Classes/FileVersionInfo.cls

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -109,16 +109,16 @@ Private Const MAX_PATH As Long = 260
109109
'the versions here are only words so drop the "d"
110110
Private Type VS_FIXEDFILEINFO
111111
dwSignature As Long
112-
wStrucVersionl As Integer ' minor
113-
wStrucVersionh As Integer 'major
114-
wFileVersionMSl As Integer ' minor
115-
wFileVersionMSh As Integer 'major
116-
wFileVersionLSl As Integer ' private
117-
wFileVersionLSh As Integer ' build
118-
wProductVersionMSl As Integer ' minor
119-
wProductVersionMSh As Integer 'major
120-
wProductVersionLSl As Integer ' private
121-
wProductVersionLSh As Integer ' build
112+
wStrucVersionl As Integer ' minor 'unsigned!
113+
wStrucVersionh As Integer 'major 'unsigned!
114+
wFileVersionMSl As Integer ' minor 'unsigned!
115+
wFileVersionMSh As Integer 'major 'unsigned!
116+
wFileVersionLSl As Integer ' private 'unsigned!
117+
wFileVersionLSh As Integer ' build 'unsigned!
118+
wProductVersionMSl As Integer ' minor 'unsigned!
119+
wProductVersionMSh As Integer 'major 'unsigned!
120+
wProductVersionLSl As Integer ' private 'unsigned!
121+
wProductVersionLSh As Integer ' build 'unsigned!
122122
dwFileFlagsMask As Long
123123
dwFileFlags As Long
124124
dwFileOS As Long
@@ -144,6 +144,7 @@ Private mProductVersion As String
144144
Private mSpecialBuild As String
145145

146146
Friend Sub New_(aPathFileName As String)
147+
Try: On Error GoTo Catch
147148
mFileName = aPathFileName
148149
If (LenB(Dir$(mFileName)) = 0) Then
149150
MsgBox "FileNotFoundException: " & mFileName
@@ -153,7 +154,7 @@ Friend Sub New_(aPathFileName As String)
153154
If (siz = 0) Then
154155
'Set GetVersionInfo = info1:
155156
End If
156-
ReDim Buffer(0 To siz - 1)
157+
ReDim Buffer(0 To siz - 1) As Byte
157158
Dim pBuffer As LongPtr: pBuffer = VarPtr(Buffer(0))
158159
If CBool(GetFileVersionInfo(StrPtr(mFileName), 0, siz, ByVal pBuffer)) Then
159160
'Debug.Print buffer1
@@ -173,6 +174,9 @@ Friend Sub New_(aPathFileName As String)
173174
End If
174175
End If
175176
'Set GetVersionInfo = info1
177+
Exit Sub
178+
Catch:
179+
MsgBox "Error in creating FileVersionInfo"
176180
End Sub
177181

178182
'in ein Modul MNew kopieren
@@ -301,7 +305,6 @@ Private Sub PtrToStructure(ByVal ptr As LongPtr, ByVal pStruct As LongPtr, ByVal
301305
RtlMoveMemory ByVal pStruct, ByVal ptr, LenBStruct
302306
End Sub
303307

304-
305308
'##############################' My Properties '##############################'
306309
'All properties ReadOnly
307310
Public Property Get FileName() As String: FileName = mFileName: End Property
@@ -317,10 +320,10 @@ Public Property Get SpecialBuild() As String: SpecialBuild = mSpecialBui
317320

318321
'##############################' Fileversion '##############################'
319322
Public Property Get FileVersion() As String: FileVersion = mFileVersion: End Property
320-
Public Property Get FileMajorPart() As Long: FileMajorPart = CLng(mVSFileInfo.wFileVersionMSh): End Property
321-
Public Property Get FileMinorPart() As Long: FileMinorPart = CLng(mVSFileInfo.wFileVersionMSl): End Property
322-
Public Property Get FileBuildPart() As Long: FileBuildPart = CLng(mVSFileInfo.wFileVersionLSh): End Property
323-
Public Property Get FilePrivatePart() As Long: FilePrivatePart = CLng(mVSFileInfo.wFileVersionLSl): End Property
323+
Public Property Get FileMajorPart() As Long: FileMajorPart = UInt16_ToInt32(mVSFileInfo.wFileVersionMSh): End Property
324+
Public Property Get FileMinorPart() As Long: FileMinorPart = UInt16_ToInt32(mVSFileInfo.wFileVersionMSl): End Property
325+
Public Property Get FileBuildPart() As Long: FileBuildPart = UInt16_ToInt32(mVSFileInfo.wFileVersionLSh): End Property
326+
Public Property Get FilePrivatePart() As Long: FilePrivatePart = UInt16_ToInt32(mVSFileInfo.wFileVersionLSl): End Property
324327

325328
'------------------------------------------------------------------
326329
Public Property Get FileDescription() As String: FileDescription = mFileDescription: End Property
@@ -329,11 +332,14 @@ Public Property Get ProductName() As String: ProductName = mProductName: End Pr
329332

330333
'##############################' Productversion '##############################'
331334
Public Property Get ProductVersion() As String: ProductVersion = mProductVersion: End Property
332-
Public Property Get ProductMajorPart() As Long: ProductMajorPart = CLng(mVSFileInfo.wProductVersionMSh): End Property
333-
Public Property Get ProductMinorPart() As Long: ProductMinorPart = CLng(mVSFileInfo.wProductVersionMSl): End Property
334-
Public Property Get ProductBuildPart() As Long: ProductBuildPart = CLng(mVSFileInfo.wProductVersionLSh): End Property
335-
Public Property Get ProductPrivatePart() As Long: ProductPrivatePart = CLng(mVSFileInfo.wProductVersionLSl): End Property
335+
Public Property Get ProductMajorPart() As Long: ProductMajorPart = UInt16_ToInt32(mVSFileInfo.wProductVersionMSh): End Property
336+
Public Property Get ProductMinorPart() As Long: ProductMinorPart = UInt16_ToInt32(mVSFileInfo.wProductVersionMSl): End Property
337+
Public Property Get ProductBuildPart() As Long: ProductBuildPart = UInt16_ToInt32(mVSFileInfo.wProductVersionLSh): End Property
338+
Public Property Get ProductPrivatePart() As Long: ProductPrivatePart = UInt16_ToInt32(mVSFileInfo.wProductVersionLSl): End Property
336339

340+
Private Function UInt16_ToInt32(ByVal uint16 As Integer) As Long
341+
If uint16 < 0 Then UInt16_ToInt32 = 65536 + uint16 Else UInt16_ToInt32 = uint16
342+
End Function
337343

338344
'##############################' Bool Props '##############################'
339345
'All properties ReadOnly

Forms/Form1.frm

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
VERSION 5.00
22
Begin VB.Form Form1
3-
Caption = "Form1"
3+
Caption = "FileVersionInfo"
44
ClientHeight = 6015
55
ClientLeft = 60
66
ClientTop = 450
@@ -68,7 +68,9 @@ Private Sub BtnInfo_Click()
6868
End Sub
6969

7070
Private Sub Form_Load()
71+
Me.Caption = Me.Caption & " v" & App.Major & "." & App.Minor & "." & App.Revision
7172
TxtFileName.Text = "C:\Windows\System32\kernel32.dll"
73+
'TxtFileName.Text = "C:\Windows\System32\msvcr100.dll"
7274
End Sub
7375

7476
Private Sub BtnFileVersion_Click()

PFileVersionInfo.vbp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Type=Exe
2-
Reference=*\G{00020430-0000-0000-C000-000000000046}#2.0#0#C:\Windows\SysWOW64\stdole2.tlb#OLE Automation
2+
Reference=*\G{00020430-0000-0000-C000-000000000046}#2.0#0#C:\WINDOWS\SysWow64\stdole2.tlb#OLE Automation
33
Form=Forms\Form1.frm
44
Class=FileVersionInfo; Classes\FileVersionInfo.cls
55
Module=MNew; Modules\MNew.bas
@@ -13,9 +13,9 @@ Command32=""
1313
Name="PFileVersionInfo"
1414
HelpContextID="0"
1515
CompatibleMode="0"
16-
MajorVer=1
17-
MinorVer=2
18-
RevisionVer=10
16+
MajorVer=2023
17+
MinorVer=6
18+
RevisionVer=26
1919
AutoIncrementVer=1
2020
ServerSupportFiles=0
2121
VersionComments="Drag'n'drop files onto the form"

0 commit comments

Comments
 (0)