Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to get executable Version Information

Status
Not open for further replies.

gleason

Programmer
Jun 2, 1999
50
US
I would like to get and display the version of a third-party, ActiveX executable called by my application. Looking in MSDEV, I have come up with the following example (actually lifted directly from the help files!):<br>
<br>
(PS - sorry about the horrible indentation)<br>
<br>
static DWORD dwVerInfoSize; <br>
static DWORD dwVerHnd; <br>
static char szGetName[256]; <br>
static WORD wRootLen; <br>
static int i; <br>
static UINT uVersionLen; <br>
static HFONT hfontDlg;<br>
static LPSTR lpVersion; <br>
BOOL bRetCode; <br>
static char szResult[256]; <br>
<br>
dwVerInfoSize = GetFileVersionInfoSize (<br>
&quot;C:\\WINDOWS\\SYSTEM\\PROGRAM.EXE&quot;,<br>
&dwVerHnd);<br>
if(dwVerInfoSize) {<br>
LPSTR lpstrVffInfo; <br>
HANDLE hMem; <br>
hMem = GlobalAlloc(GMEM_MOVEABLE, dwVerInfoSize);<br>
lpstrVffInfo = (char *)GlobalLock(hMem);<br>
bRetCode = GetFileVersionInfo<br>
(&quot;C:\\WINDOWS\\SYSTEM\\PROGRAM.EXE&quot;,<br>
dwVerHnd,<br>
dwVerInfoSize, <br>
lpstrVffInfo);<br>
wRootLen = lstrlen(szGetName); <br>
uVersionLen = 0;<br>
lpVersion = NULL;<br>
bRetCode = VerQueryValue((LPVOID)lpstrVffInfo,<br>
TEXT(&quot;\\StringFileInfo\\040904E4\\FileVersion&quot;,<br>
(LPVOID *)&lpVersion, <br>
(PUINT)&uVersionLen);<br>
<br>
if (bRetCode && uVersionLen && lpVersion)<br>
lstrcpy(szResult, lpVersion);<br>
<br>
GlobalUnlock(hMem);<br>
GlobalFree(hMem);<br>
} // if (dwVerInfoSize)<br>
<br>
What Happens:<br>
<br>
When I call GetFileVersionInfoSize, dwVerInfoSize is always assigned the value of 983. (good, I think)<br>
<br>
When I call GetFileVersionInfo, bRetCode is 1 (TRUE) and <br>
lpstrVffInfo gets set.<br>
<br>
BUT when I call VerQueryValue, bRetCode is 0, lpVersion is <br>
NULL and uVersionLen is zero. I have tried changing the<br>
second parameter to File Version, FileDescription, File<br>
Description, all with the exact same results. <br>
<br>
Can you help me out?<br>
<br>
Thanks much!<br>
<br>
<br>
<p>Pat Gleason<br><a href=mailto:gleason@megsinet.net>gleason@megsinet.net</a><br><a href= > </a><br>
 
You could try another codepage when calling VerQueryValue.<br>
<br>
"...\\StringFileInfo\\040904E4\\FileVersion..."<br>
<br>
// 04------ = SUBLANG_ENGLISH_USA<br>
// --XX---- = Language ID (*)<br>
// ----04E4 = 1252 = Codepage for Windows:Multilingual<br>
// ----04B0 = 1200 = Codepage for unicode<br>
<br>
Usually 0x09 (=English), but check with GetSystemDefaultLangID().<br>
<br>
Try at least the 04E4 and 04B0 codepages, call VerQueryValue with both the 040904E4 and 040904B0 stings.<br>

 
Thank you iGOR -- it worked!<br>
<br>
First I added a call to GetSystemDefaultLangID() but that returned 0409 (what I was already using). <br>
<br>
Then, I changed the code page from 04E4 to 04B0 and I get the version number that I'm looking for.<br>
<br>
Thanks again!<br>
<p>Pat Gleason<br><a href=mailto:gleason@megsinet.net>gleason@megsinet.net</a><br><a href= > </a><br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top