Calling GetFileVersionInfo()

BlitzMax Forums/BlitzMax Programming/Calling GetFileVersionInfo()

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

Get a copy of MinGW and link to libversion.a.

As for getting the version -- it's painful:
Import "-lversion"
Extern "OS"
    Function GetFileVersionInfoSizeW%( f$w, h% Var )
    Function GetFileVersionInfoW%( f$w, h%, dwlen%, data@ Ptr )
    Function VerQueryValueW%( data@ Ptr, sub$w, outp@ Ptr Var, size% Var )
End Extern

Local file$ = "C:\WINDOWS\explorer.exe"
Local h%
Local s% = GetFileVersionInfoSizeW( file, h )

Assert s>0,"Failed to get version data size"

Local data@[s]

Assert GetFileVersionInfoW( file, 0, s, data ),"Failed to get version info"

Local d@ Ptr
Local languages%
Local langData@ Ptr
Assert VerQueryValueW( data, "\VarFileInfo\Translation", langData, languages ), "Failed to get file version pointer"

For Local i% = 0 To (languages/4)-1
    Local lang$ = Hex(Int Ptr(langData)[i]).ToLower( )
    lang = lang[4..]+lang[..4] ' Swap the shorts around
    
    If Not VerQueryValueW( data, "\StringFileInfo"+lang+"\FileVersion", d, s ) Then
        Print "Failed to get data"
        Continue
    EndIf
    
    If s = 0 Then
        Print "No data to read."
        Continue
    EndIf
    
    Print String.FromShorts( Short Ptr( d ), s )
Next

Input
End