Post by (X) on Mar 14, 2023 16:50:34 GMT 1
All I wanted to do was go a little bit out of my comfort zone and see if I could do something as simple as getting the file version information of a DLL file using GFA-Basic 32 code.
You can also get this information if you right click on the file and check the detail properties.
After about 48 hrs of trials & tribulations and a lot of head scratching... I finally succeeded in getting the demo from the internet to work under GFA.
I kept failing on the last step until I tried another way of copying memory data from a Byte array to a User Data Typed variable's memory area. I guess you might call this updating a 'record' from memory.
I succeded when I tried MemMove instead of the suggested MemCpy command. This lead me to finding a 'good to know' & 'wish I had known' quirk of GFA's built-in MemCpy command. See: gb32.proboards.com/thread/591/tip-using-memcpy-dst-src.
'#################################################################################
'
' DISCLAIMER: THIS CODE IS OFFERED AS IS FOR EDUCATIONAL PURPOSES.
' YOU ARE FREE TO USE, COPY AND DISTRIBUTE.
' THE USE OF THIS CODE IS AT YOUR OWN RISK.
' I ACCEPT NO LIABILITY NOR MAKE ANY CLAIM OF
' CORRECTNESS OR SUITABILITY IN PART OR IN WHOLE.
'
'#################################################################################
'
' FILENAME Demo GetFileVersion.G32
'
' DESCRIPTION Can you get the file version of a DLL or other file in code?
' This is an experimental setup sourced from all over the internet.
'
' AUTHOR (X)
' EMAIL xman.gb32@gmail.com
' WEBSITE https://gfabasic32.blogspot.com/
' FORUM https://gb32.proboards.com/
' STARTED 2023-03-12
' UPDATED 2023-03-14
'
'
$Library "GfaWinX"
$Library "UpdateRT"
UpdateRuntime
Mode Date "-"
°Type T_FIXEDFILEINFO
°dwSignature As Long
°dwStrucVersion As Long
°dwFileVersionMS As Long
°dwFileVersionLS As Long
°dwProductVersionMS As Long
°dwProductVersionLS As Long
°dwFileFlagsMask As Long
°dwFileFlags As Long
°dwFileOS As Long
°dwFileType As Long
°dwFileSubtype As Long
°dwFileDateMS As Long
°dwFileDateLS As Long
°EndType
Type T_FIXEDFILEINFO
dwSignature As Long
dwStrucVersionl As Short ' e.g. = &h0000 = 0
dwStrucVersionh As Short ' e.g. = &h0042 = .42
dwFileVersionMSl As Short ' e.g. = &h0003 = 3
dwFileVersionMSh As Short ' e.g. = &h0075 = .75
dwFileVersionLSl As Short ' e.g. = &h0000 = 0
dwFileVersionLSh As Short ' e.g. = &h0031 = .31
dwProductVersionMSl As Short ' e.g. = &h0003 = 3
dwProductVersionMSh As Short ' e.g. = &h0010 = .10
dwProductVersionLSl As Short ' e.g. = &h0000 = 0
dwProductVersionLSh As Short ' e.g. = &h0031 = .31
dwFileFlagsMask As Long ' = &h3F for version "0.42"
dwFileFlags As Long ' e.g. VFF_DEBUG Or VFF_PRERELEASE
dwFileOS As Long ' e.g. VOS_DOS_WINDOWS16
dwFileType As Long ' e.g. VFT_DRIVER
dwFileSubtype As Long ' e.g. VFT2_DRV_KEYBOARD
dwFileDateMS As Long ' e.g. 0
dwFileDateLS As Long ' e.g. 0
End Type
Trace GetFileVersion("odbc32.dll")
Function GetFileVersion(ByVal sFileName As String) As String
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Get the size of the file version information
'
Declare Function GetFileVersionInfoSize Lib "version.dll" Alias "GetFileVersionInfoSizeW" ( _
ByVal lptstrFilename As String, _
ByVal lpdwHandle As Long) As Long
Trace sFileName
Local Long dwHandle = 0
Trace GetFileVersionInfoSize(Wide(sFileName), dwHandle)
Local Long versionInfoSize = GetFileVersionInfoSize(Wide(sFileName), dwHandle)
Trace versionInfoSize
Local VI_Chr_Cnt = versionInfoSize / 2
Trace VI_Chr_Cnt
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Create a Byte Buffer to store the file version information
'
Local Byte VI_Bytes()
ReDim VI_Bytes(0 To VI_Chr_Cnt - 1) : ArrayFill VI_Bytes(), 0
Local Long lp_VI_Bytes = V:VI_Bytes(0)
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Put the file version information into a Byte buffer via Long Pointer Address...
'
Declare Function GetFileVersionInfo Lib "version.dll" Alias "GetFileVersionInfoW" ( _
ByVal lptstrFilename As String, _
ByVal dwHandle As Long, _
ByVal dwLen As Long, _
ByVal lpData As Any) As Long
Trace GetFileVersionInfo(Wide(sFileName), dwHandle, versionInfoSize, VI_Bytes(0))
Trace Hex( lp_VI_Bytes)
Debug HexDump(lp_VI_Bytes, VI_Chr_Cnt)
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Get a block of file version information via query string parameter.
'
'Local s$ = Wide("\")
'Local s$ = Wide("\")
'Local s$ = Wide("\\FileVersion\\")
'Local s$ = Wide("\\StringFileInfo\\040904E4\\FileVersion")
'Local s$ = Wide("\\")
'Local s$ = Wide("\\Size\\")
'Local s$ = "\"
Local s$ = ""
Declare Function VerQueryValue Lib "version.dll" Alias "VerQueryValueA" ( _
ByVal pBlock As Any, _
ByVal lpSubBlock As String, _
ByVal lplpBuffer As Any, _
ByVal puLen As Long) As Long
Local Long FileInfoSize = Len(T_FIXEDFILEINFO)
Local FileInfo As T_FIXEDFILEINFO
Local Long lpFileInfo = V:FileInfo
Local Long lpVerFileInfo
Local Long VerBufLen
Local Long lpVerBufLen = V:VerBufLen
Trace VerQueryValue(VI_Bytes(0), s$, lpVerFileInfo, lpVerBufLen)
Trace Hex(lpVerFileInfo)
Trace Hex(lpVerBufLen)
Trace VerBufLen
Debug "HexDump(lpVerFileInfo, VerBufLen)"
Debug HexDump(lpVerFileInfo, VerBufLen)
Trace Hex(lpFileInfo)
Trace FileInfoSize
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' MoveMemory udtVerBuffer, lVerPointer, Len(udtVerBuffer)
'
' !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
' Nota Bene: It is worth noting that MemCpy dst, src, cnt will not work as
' expected with a variable or function for cnt, as the src and dst are swapped
' only a literal or a constant. Son of a $%^&*! This kept me up 'til 2AM last
' night and I just debugged this at 10 AM having gotten up at 8AM this morning.
' !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
'
Debug "MemMove lpFileInfo, lpVerFileInfo, VerBufLen"
MemMove lpFileInfo, lpVerFileInfo, VerBufLen
Debug "HexDump(lpFileInfo, FileInfoSize)"
Debug HexDump(lpFileInfo, FileInfoSize)
Trace FileInfoSize
Trace FileInfo
Dim StrucVer$, FileVer$, ProdVer$
With FileInfo
'**** Determine Structure Version number - NOT USED ****
StrucVer = Format$(.dwStrucVersionh) & "." & Format$(.dwStrucVersionl)
'**** Determine File Version number ****
FileVer = Format$(.dwFileVersionMSh) & "." & Format$(.dwFileVersionMSl) & "." _
& Format$(.dwFileVersionLSh) & "." & Format$(.dwFileVersionLSl)
'**** Determine Product Version number ****
ProdVer = Format$(.dwProductVersionMSh) & "." & Format$(.dwProductVersionMSl) _
& "." & Format$(.dwProductVersionLSh) & "." & Format$(.dwProductVersionLSl)
EndWith
Return "StrucVer:" & StrucVer & ", FileVer:" & FileVer & ", ProdVer:" & ProdVer
EndFunction