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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Version information about ActiveX EXE 1

Status
Not open for further replies.

gleason

Programmer
Jun 2, 1999
50
0
0
US
This may be similar to the question posted about a month ago by &quot;seyed&quot;.<br>
<br>
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>
Pat Gleason<br>
<A HREF="mailto:gleason@megsinet.net">gleason@megsinet.net</A><br>
<p>Pat Gleason<br><a href=mailto:gleason@megsinet.net>gleason@megsinet.net</a><br><a href= > </a><br>
 
<br>
Is this a 16-bit Active-x executable (.dll, .exe)? The version info functions in Win32 don't seem to be able to see the verinfo on a 16-bit executable. I don't know how MS does it, since you can use the shell to display it (right-click, properties, version). But other than that, your code looks pretty good. Here's my old VB4 16-bit code to do it, you should be able to modify it to 32-bit standards. I'm a little embarassed by the code now, but it's worked for years...<br>
<br>
<br>
Declare Function GetFileVersionInfoSize Lib &quot;ver.dll&quot; (ByVal lpszFileName As String, lpdwHandle As Long) As Long<br>
Declare Function GetFileVersionInfo Lib &quot;ver.dll&quot; (ByVal lpszFileName As String, ByVal lpdwHandle As Long, ByVal cbbuf As Long, ByVal lpvdata As String) As Integer<br>
Declare Function VerQueryValue Lib &quot;ver.dll&quot; (ByVal lpvBlock As String, ByVal lpszSubBlock As String, lplpBuffer As Long, lpcb As Integer) As Integer<br>
Declare Function lstrcpyn Lib &quot;Kernel&quot; (ByVal lpszString1 As Any, ByVal lpszString2 As Long, ByVal cChars As Integer) As Long<br>
<br>
Global Const LOCATION_WIN = 1<br>
Global Const LOCATION_WINSYS = 2<br>
Global Const LOCATION_APP = 3<br>
Global Const LOCATION_ROOT = 4<br>
<br>
Public Const WF_80x87 = &H400<br>
Public Const WF_CPU086 = &H40<br>
Public Const WF_CPU186 = &H80<br>
Public Const WF_CPU286 = &H2<br>
Public Const WF_CPU386 = &H4<br>
Public Const WF_CPU486 = &H8<br>
Public Const WF_ENHANCED = &H20<br>
Public Const WF_STANDARD = &H10<br>
<br>
Type ModuleInfoType<br>
ModuleName As String<br>
Location As Integer<br>
Version As String<br>
Size As String<br>
FDate As String<br>
End Type<br>
<br>
<br>
'*******************************************************<br>
Function GetFileVersion$(FileToCheck$)<br>
Dim lpdwHandle&, VersionInfoSize&, lplpBuffer&, StrCpy&, TransValue&<br>
Dim lpvdata$, TransString$, FixedStr$, Char$, NextChar$, TransTable$<br>
Dim VersionInfo%, lpcb%, ptrFixed%, pString%, i%, ZeroLoc%<br>
<br>
On Error Resume Next<br>
<br>
'Find out if version info is present<br>
VersionInfoSize& = GetFileVersionInfoSize(FileToCheck$, lpdwHandle&)<br>
<br>
If VersionInfoSize& = 0 Then<br>
'Version info not present<br>
GetFileVersion$ = &quot;&quot;<br>
Exit Function '&lt;-------<br>
End If<br>
<br>
'Pre-Allocate a string the same size as the VersionInfo, then get the info itself<br>
lpvdata$ = String(VersionInfoSize&, Chr$(0))<br>
VersionInfo% = GetFileVersionInfo(FileToCheck$, lpdwHandle&, VersionInfoSize&, lpvdata$)<br>
<br>
ptrFixed% = VerQueryValue(lpvdata$, &quot;\FILEVERSION&quot;, lplpBuffer&, lpcb%)<br>
<br>
If ptrFixed% = 0 Then<br>
' Take a shot with the hardcoded TransString<br>
TransString$ = &quot;040904E4&quot;<br>
pString% = VerQueryValue(lpvdata$, &quot;\StringFileInfo\&quot; & TransString$ & &quot;\CompanyName&quot;, lplpBuffer&, lpcb%)<br>
<br>
If pString% &lt;&gt; 0 Then<br>
GoTo GetValues<br>
End If<br>
<br>
ptrFixed% = VerQueryValue(lpvdata$, &quot;\&quot;, lplpBuffer&, lpcb%)<br>
<br>
If ptrFixed% = 0 Then<br>
GetFileVersion$ = &quot;&quot;<br>
Exit Function '&lt;-------<br>
Else<br>
TransString$ = &quot;&quot;<br>
FixedStr$ = String(lpcb% + 1, Chr(0))<br>
StrCpy& = lstrcpyn(FixedStr$, lplpBuffer&, lpcb% + 1)<br>
<br>
For i% = lpcb% To 1 Step -1<br>
Char$ = Hex(Asc(Mid(FixedStr$, i%, 1)))<br>
<br>
If Len(Char$) = 1 Then<br>
Char$ = &quot;0&quot; + Char$<br>
End If<br>
<br>
TransString$ = TransString$ + Char$<br>
<br>
If Len(TransString$ & NextChar$) Mod 8 = 0 Then<br>
TransString$ = &quot;&H&quot; & TransString$<br>
TransValue& = Val(TransString$)<br>
TransString$ = &quot;&quot;<br>
End If<br>
<br>
Next i%<br>
End If<br>
End If<br>
<br>
TransTable$ = String(lpcb% + 1, Chr(0))<br>
TransString$ = String(0, Chr(0))<br>
StrCpy& = lstrcpyn(TransTable$, lplpBuffer&, lpcb% + 1)<br>
<br>
For i = 1 To lpcb%<br>
Char$ = Hex(Asc(Mid(TransTable$, i, 1)))<br>
<br>
If Len(Char$) = 1 Then<br>
Char$ = &quot;0&quot; + Char$<br>
End If<br>
<br>
If Len(TransString$ & NextChar$) Mod 4 = 0 Then<br>
NextChar$ = Char$<br>
Else<br>
TransString$ = TransString$ + Char$ + NextChar$<br>
NextChar$ = &quot;&quot;<br>
Char$ = &quot;&quot;<br>
End If<br>
Next i<br>
<br>
GetValues:<br>
pString% = VerQueryValue(lpvdata$, &quot;\StringFileInfo\&quot; & TransString$ & &quot;\FileVersion&quot;, lplpBuffer&, lpcb%)<br>
<br>
If pString% = 1 Then<br>
TransTable$ = String(lpcb%, Chr(0))<br>
StrCpy& = lstrcpyn(TransTable$, lplpBuffer&, lpcb% + 1)<br>
<br>
'Convert all nulls to spaces<br>
ZeroLoc% = InStr(TransTable$, Chr$(0))<br>
While ZeroLoc% &gt; 0<br>
Mid$(TransTable$, ZeroLoc%, 1) = &quot; &quot;<br>
ZeroLoc% = InStr(TransTable$, Chr$(0))<br>
Wend<br>
<br>
GetFileVersion$ = TransTable$<br>
Else<br>
GetFileVersion$ = &quot;&quot;<br>
End If<br>
<br>
End Function<br>
<br>
<br>
Chip H.<br>

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top