News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Getting my file version

Started by Jimg, August 05, 2009, 07:03:11 PM

Previous topic - Next topic

Jimg

After spending several very frustrating hours researching GetFileVersionInfo and it's gobledygook routines, I realized,  I put the version in the resource file, I know it's there.

I use WinAsm Studio which autoincrements the file version for me each time I assemble.  To get the current file version for printing or whatever-


Quote
uselib version
.data?
hInst dd ?
CurVersion dd ?
tmp dd ?
MyVersionResourceID equ 1
.code
    inv GetModuleHandle,0
    mov hInst,eax


        invoke FindResource,hInst,MyVersionResourceID ,RT_VERSION
        invoke LoadResource,hInst,eax
        invoke LockResource,eax
        mov edx,eax
        invoke VerQueryValue,edx,SADD("\StringFileInfo\040904E4\FileVersion"),addr CurVersion,addr tmp


       invoke MessageBox,0,CurVersion,0,0  ; test the results

CurVersion now contains the address of the string containing version number.

Slugsnack

this is how i do it :

invoke GetFileVersionInfoSize, addr szCurrentDir, addr dwHistoricalHandle
push eax
mov hMem, alloc(eax)
pop eax
invoke GetFileVersionInfo, addr szCurrentDir, NULL, eax, hMem
invoke VerQueryValue, hMem, chr$("\StringFileInfo\08090000\FileVersion"), addr lpBuffer, dwHistoricalHandle
invoke RtlZeroMemory, addr szAbout, 256
mov eax, add$(addr szAbout, chr$("Coded by **** ****", 13, 10))
mov eax, add$(addr szAbout, chr$("Current version is : "))
mov eax, add$(addr szAbout, lpBuffer)
invoke ShellAbout, hwndDlg, chr$("IP Tool"), addr szAbout, NULL
free hMem

fearless

I use the following code to read the exe and get the product version, it can be used on the current exe by calling GetModuleFileName before and passing the result of that to the GetFileVersion function, or by passing the filename.exe of another file  (exe, dll, etc), located on the disk somewhere.

GetFileVersion PROTO :DWORD, :DWORD

.code
;**************************************************************************
; Gets the product version from a specified file and returns it as a
; dword pointer to the zero terminated string in cFileVersion
; returns TRUE if succesfull or FALSE if no string retrieved.
; cFileVersion will contain the string value of the version information
;**************************************************************************
GetFileVersion PROC cFilename:DWORD, cFileVersion:DWORD

LOCAL buffer[255]:BYTE
LOCAL lpdwHandle:DWORD
LOCAL nbytes:DWORD
LOCAL hHeap:DWORD
LOCAL pMem:DWORD
LOCAL pLang:DWORD
LOCAL dwChar:DWORD
LOCAL hFile:DWORD
LOCAL pszProductVersion:DWORD

Invoke szLen, cFilename ; if empty
.IF eax == 0
mov eax, FALSE
ret
.endif

Invoke exist, cFilename
.if eax == 0
mov eax, FALSE
ret
.endif

invoke GetFileVersionInfoSize, cFilename, addr lpdwHandle

.if eax!=0
mov nbytes,eax
invoke GetProcessHeap
.if eax!=0
mov hHeap,eax
invoke HeapAlloc,eax,0,nbytes
.if eax!=0
mov pMem,eax
invoke GetFileVersionInfo, cFilename, 0, nbytes, pMem
.if eax!=0

invoke VerQueryValue,pMem,CTEXT("\VarFileInfo\Translation"),addr pLang,addr dwChar
.if eax!=0 && dwChar!=0

mov eax,pLang
movzx ecx,[eax.LANGANDCODEPAGE].wLanguage
movzx edx,[eax.LANGANDCODEPAGE].wCodepage

invoke wsprintf,addr buffer,CTEXT("\StringFileInfo\%04x%04x\ProductVersion"),ecx,edx
invoke VerQueryValue,pMem,addr buffer, Addr pszProductVersion,addr dwChar
.if eax!=0 && dwChar!=0
invoke szCopy, pszProductVersion, cFileVersion
invoke HeapFree,hHeap,0,pMem
mov eax, TRUE
ret
.else
invoke HeapFree,hHeap,0,pMem
.endif
.endif
.endif
.endif
.endif
.endif
mov eax, FALSE
ret

GetFileVersion ENDP
ƒearless