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>
"C:\\WINDOWS\\SYSTEM\\PROGRAM.EXE",<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>
("C:\\WINDOWS\\SYSTEM\\PROGRAM.EXE",<br>
dwVerHnd,<br>
dwVerInfoSize, <br>
lpstrVffInfo);<br>
wRootLen = lstrlen(szGetName); <br>
uVersionLen = 0;<br>
lpVersion = NULL;<br>
bRetCode = VerQueryValue((LPVOID)lpstrVffInfo,<br>
TEXT("\\StringFileInfo\\040904E4\\FileVersion",<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>
<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>
"C:\\WINDOWS\\SYSTEM\\PROGRAM.EXE",<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>
("C:\\WINDOWS\\SYSTEM\\PROGRAM.EXE",<br>
dwVerHnd,<br>
dwVerInfoSize, <br>
lpstrVffInfo);<br>
wRootLen = lstrlen(szGetName); <br>
uVersionLen = 0;<br>
lpVersion = NULL;<br>
bRetCode = VerQueryValue((LPVOID)lpstrVffInfo,<br>
TEXT("\\StringFileInfo\\040904E4\\FileVersion",<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>