Since a couple of days I have contend with difficulties to retrieve file information. Reading and testing but no success. This is last attempt.
invoke GetFileVersionInfoSize,addr szComToolExe,addr lpdwHandle

.if eax!=0
mov nbytes,eax
invoke GetFileVersionInfo,addr szComToolExe,0,sizeof buffer,addr buffer
.if eax!=0
.data
szLang db "\VarFileInfo\Translation",0
szInfo db "\StringFileInfo\%04x%04x\CompanyName",0
.code
invoke VerQueryValue,addr buffer,addr szLang,addr lang,addr dwChar
.if eax!=0 && dwChar!=0
invoke wsprintf,addr buffer2,addr szInfo,lang.wLanguage,lang.wCodepage
add esp,4
invoke VerQueryValue,addr buffer,addr buffer2,addr InfoOut,addr dwChar
.if eax!=0 && dwChar!=0
invoke MessageBox,0,addr InfoOut,0,MB_OK
.endif
.endif
.endif
.endif
The second "VerQueryValue" returns zero and the dwChar is also zero. The info is retrieved and hold in buffer but I can't get it to messagebox. Any suggestions?

Best regards
Posted on 2004-11-13 09:17:23 by minor28

invoke wsprintf,addr buffer2,addr szInfo,lang.wLanguage,lang.wCodepage

add esp,4


1. WORD paremeters passed to wsprintf() (wLanguage and wCodepage) need to be passed as DWORDs.
2. Remove the 'add esp, 4' line.
Posted on 2004-11-13 09:46:40 by death
Thanks death,

New code.
LANGANDCODEPAGE STRUCT 

wLanguage word ?
wCodepage word ?
LANGANDCODEPAGE ends

invoke GetFileVersionInfoSize,addr szComToolExe,addr lpdwHandle
.if eax!=0
mov nbytes,eax
invoke GetFileVersionInfo,addr szComToolExe,0,sizeof buffer,addr buffer
.if eax!=0
.data
szLang db "\VarFileInfo\Translation",0
szInfo db "\StringFileInfo\%04x%04x\CompanyName",0
.code
invoke VerQueryValue,addr buffer,addr szLang,addr lang,addr dwChar
.if eax!=0 && dwChar!=0
movzx ecx,lang.wLanguage
movzx edx,lang.wCodepage
invoke wsprintf,addr buffer2,addr szInfo,ecx,edx
invoke VerQueryValue,addr buffer,addr buffer2,addr InfoOut,addr dwChar
.if eax!=0 && dwChar!=0
invoke MessageBox,0,addr InfoOut,0,MB_OK
.endif
.endif
.endif
.endif


Same resut.
Posted on 2004-11-13 09:55:05 by minor28
third parameter of VarQueryValue is a pointer to a pointer.

Possibly it must be done this way:



invoke VerQueryValue,addr buffer,addr szLang,addr pVoid,addr dwChar
.if eax!=0 && dwChar!=0
mov eax, pVoid
movzx ecx,[eax].LANGANDCODEPAGE.wLanguage
movzx edx,[eax].LANGANDCODEPAGE.wCodepage


Just a guess
Posted on 2004-11-13 10:37:54 by japheth
Here's a correct version:
ShowCompanyName PROC filename:LPSTR

LOCAL handle:DWORD
LOCAL infoSize:DWORD
LOCAL heap:HANDLE
LOCAL infoBlock:LPVOID
LOCAL lang:DWORD
LOCAL len:DWORD
LOCAL infoSubBlock[256]:BYTE
LOCAL companyName:DWORD

invoke GetFileVersionInfoSize, filename, ADDR handle
.IF eax != 0
mov infoSize, eax
invoke GetProcessHeap
.IF eax != 0
mov heap, eax
invoke HeapAlloc, eax, 0, infoSize
.IF eax != 0
mov infoBlock, eax
invoke GetFileVersionInfo, filename, handle, infoSize, infoBlock
.IF eax != 0
.const
langSubBlock db '\VarFileInfo\Translation', 0
infoSubBlockFmt db '\StringFileInfo\%04x%04x\CompanyName', 0
.code
invoke VerQueryValue, infoBlock, ADDR langSubBlock, ADDR lang, ADDR len
.IF eax != 0 && len != 0
mov eax, lang
movzx ecx, word ptr [eax].LANGANDCODEPAGE.language
movzx edx, word ptr [eax].LANGANDCODEPAGE.codepage
invoke wsprintf, ADDR infoSubBlock, ADDR infoSubBlockFmt, ecx, edx
invoke VerQueryValue, infoBlock, ADDR infoSubBlock, ADDR companyName, ADDR len
.IF eax != 0 && len != 0
invoke MessageBox, 0, companyName, 0, MB_OK
.ENDIF
.ENDIF
.ENDIF
invoke HeapFree, heap, 0, infoBlock
.ENDIF
.ENDIF
.ENDIF

ret
ShowCompanyName ENDP
Posted on 2004-11-13 11:10:38 by death
Thanks death and japheth,

Now it works. It only works if you allocate memory. A question though. Do you have to allocate memory because of the fact that version info is wide character string format?

This is the code:
invoke GetFileVersionInfoSize,addr szComToolExe,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,addr szComToolExe,0,nbytes,pMem
.if eax!=0
.data
szLang db "\VarFileInfo\Translation",0
szInfo db "\StringFileInfo\%04x%04x\CompanyName",0
.code
invoke VerQueryValue,pMem,addr szLang,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,addr szInfo,ecx,edx
invoke VerQueryValue,pMem,addr buffer,addr InfoOut,addr dwChar
.if eax!=0 && dwChar!=0
invoke MessageBox,0,InfoOut,0,MB_OK
.endif
.endif
.endif
invoke HeapFree,hHeap,0,pMem
.endif
.endif
.endif

Best regards
Posted on 2004-11-13 15:09:23 by minor28
I dynamically allocate memory because the file version information block size isn't known at assemble-time.

It didn't work because of the reason japheth described, and also, perhaps the buffer wasn't big enough to include the company name information.
Posted on 2004-11-13 15:28:37 by death