home *** CD-ROM | disk | FTP | other *** search
- VERSION 4.00
- Begin VB.Form FileDemo
- Caption = "File Demo"
- ClientHeight = 2520
- ClientLeft = 1095
- ClientTop = 1770
- ClientWidth = 4980
- BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851}
- Name = "MS Sans Serif"
- Size = 8.25
- Charset = 0
- Weight = 700
- Underline = 0 'False
- Italic = 0 'False
- Strikethrough = 0 'False
- EndProperty
- ForeColor = &H80000008&
- Height = 3210
- Left = 1035
- LinkMode = 1 'Source
- LinkTopic = "Form1"
- ScaleHeight = 2520
- ScaleWidth = 4980
- Top = 1140
- Width = 5100
- Begin VB.DirListBox Dir1
- Height = 1380
- Left = 240
- TabIndex = 1
- Top = 720
- Width = 2295
- End
- Begin VB.FileListBox File1
- Height = 1785
- Left = 2760
- Pattern = "*.exe;*.dll;*.vbx"
- TabIndex = 2
- Top = 240
- Width = 1935
- End
- Begin VB.DriveListBox Drive1
- Height = 315
- Left = 240
- TabIndex = 0
- Top = 240
- Width = 2295
- End
- Begin VB.Menu MenuInformation
- Caption = "Information"
- Begin VB.Menu MenuDevices
- Caption = "Devices"
- End
- Begin VB.Menu MenuPrinters
- Caption = "Printers"
- End
- Begin VB.Menu MenuVersionInfo
- Caption = "Version Info"
- End
- Begin VB.Menu MenuVersionDesc
- Caption = "Version Desc:"
- End
- End
- Attribute VB_Name = "FileDemo"
- Attribute VB_Creatable = False
- Attribute VB_Exposed = False
- Option Explicit
- ' Copyright
- 1997 by Desaware Inc. All Rights Reserved
- ' Breaks a 32 bit version into major and minor revs, then
- ' then returns the string representation.
- Private Function CalcVersion$(vernum&)
- Dim major%, minor%
- major% = CInt(vernum& / &H10000)
- minor% = CInt(vernum& And &HFFFF&)
- CalcVersion$ = Str$(major%) + "." + LTrim$(Str$(minor%))
- End Function
- Private Sub Dir1_Change()
- File1.Path = Dir1.Path
- End Sub
- Private Sub Drive1_Change()
- Dir1.Path = drive1.Drive
- End Sub
- Private Sub File1_Click()
- Dim fressize&
- Dim freshnd&
- Dim di&
- ' Build the file name
- If Right$(Dir1.Path, 1) = "\" Then
- FileName$ = Dir1.Path + File1.FileName
- Else
- FileName$ = Dir1.Path + "\" + File1.FileName
- End If
- ' Determine if version information is present, and
- ' if so how large a buffer is needed to hold it.
- fressize& = GetFileVersionInfoSize(FileName$, freshnd&)
- ' The following code from the VB3 version is no longer needed
- 'If fressize& = 0 Then
- ' verbuf$ = ""
- ' Exit Sub
- 'End If
- ' Version info is unlikely to ever be greater than 64k
- ' but check anyway. If it was larger than 64k, we would
- ' need to allocate a huge buffer instead. Note, we
- ' are only using an approximation to 64k here to take
- ' into account the VB string overhead.
- If fressize& > 64000 Then fressize& = 64000
- 'Was: verbuf$ = String$(CInt(fressize&) + 1, Chr$(0))
- ReDim verbuf(fressize + 1)
- ' Load the string with the version information
- ' In Win16, we used the address of the string
- ' Was: di% = GetFileVersionInfo(FileName$, freshnd&, fressize&, agGetAddressForVBString&(verbuf$))
- di = GetFileVersionInfo(FileName$, freshnd&, fressize&, verbuf(0))
- ' The menu commands will use the information global
- ' in this global version buffer.
- If di = 0 Then ReDim verbuf(1) ' Error occured
- End Sub
- Private Function GetInfoString$(stringtoget$)
- Dim tbuf$
- Dim nullpos%
- Dim xlatelang%
- Dim xlatecode%
- Dim numentries%
- Dim fiiaddr&
- Dim xlatestring$
- Dim xlateval&
- #If Win32 Then
- Dim fiilen&
- Dim di&
- #Else
- Dim fiilen%
- Dim di%
- #End If
- Dim x%
- di = VerQueryValue(verbuf(0), "\VarFileInfo\Translation", fiiaddr&, fiilen)
- If (di <> 0) Then ' Translation table exists
- numentries% = fiilen / 4
- xlateval& = 0
- For x% = 1 To numentries%
- ' Copy the 4 byte tranlation entry for the first
- agCopyData ByVal fiiaddr&, xlatelang%, 2
- agCopyData ByVal (fiiaddr& + 2), xlatecode%, 2
- ' Exit if U.S. English was found
- If xlatelang% = &H409 Then Exit For
- fiiaddr& = fiiaddr& + 4
- Next x%
- Else
- ' No translation table - Assume standard ASCII
- xlatelang% = &H409
- xlatecode% = 0
- End If
- xlatestring$ = Hex$(xlatecode%)
- ' Make sure hex string is 4 chars long
- While Len(xlatestring$) < 4
- xlatestring$ = "0" + xlatestring$
- Wend
- xlatestring$ = Hex$(xlatelang%) + xlatestring$
- ' Make sure hex string is 8 chars long
- While Len(xlatestring$) < 8
- xlatestring$ = "0" + xlatestring$
- Wend
- di = VerQueryValue(verbuf(0), "\StringFileInfo\" + xlatestring$ + "\" + stringtoget$, fiiaddr&, fiilen)
- If di = 0 Then
- GetInfoString$ = "Unavailable"
- Exit Function
- End If
- tbuf$ = String$(fiilen + 1, Chr$(0))
- ' Copy the fixed file info into the structure
- agCopyData ByVal fiiaddr&, ByVal tbuf$, fiilen
- nullpos% = InStr(tbuf$, Chr$(0))
- If (nullpos% > 1) Then
- GetInfoString$ = Left$(tbuf$, nullpos% - 1)
- Else
- GetInfoString$ = "None"
- End If
- End Function
- Private Sub MenuDevices_Click()
- ShowDevices
- End Sub
- Private Sub MenuPrinters_Click()
- ShowPrinters
- End Sub
- Private Sub MenuVersionDesc_Click()
- ShowDescInfo
- End Sub
- Private Sub MenuVersionInfo_Click()
- ShowVersionInfo
- End Sub
- ' This function shows how to obtain other information about
- ' a file.
- Private Sub ShowDescInfo()
- Dim res$, crlf$
- crlf$ = Chr$(13) + Chr$(10)
- If UBound(verbuf) < 2 Then
- MsgBox "No version information available for this file"
- Exit Sub
- End If
- res$ = "Company: " + GetInfoString$("CompanyName") + crlf$
- res$ = res$ + "File Desc: " + GetInfoString$("FileDescription") + crlf$
- res$ = res$ + "Copyright: " + GetInfoString$("LegalCopyright") + crlf$
- res$ = res$ + "FileVersion: " + GetInfoString$("FileVersion") + crlf$
- MsgBox res$, 0, "Fixed Version Info"
- End Sub
- ' Lists all devices in the WIN.INI file
- Private Sub ShowDevices()
- Dim devstring As String * 4096
- Dim startpos%, endpos%
- Dim crlf$
- Dim res$
- Dim di&
- crlf$ = Chr$(13) + Chr$(10)
- di = GetProfileString("devices", 0&, "", devstring, 4095)
- If di = 0 Then
- MsgBox "Win.ini does not contain devices field under this OS"
- Exit Sub
- End If
- startpos% = 1
- Do While (Asc(Mid$(devstring, startpos%, 1)) <> 0)
- endpos% = InStr(startpos%, devstring, Chr$(0))
- res$ = res$ + Mid$(devstring, startpos%, endpos% - startpos%) + crlf$
- startpos% = endpos% + 1
- Loop
- MsgBox res$, 0, "Devices"
- End Sub
- ' Show information from the fixed version info for the
- ' current file.
- Private Sub ShowVersionInfo()
- Dim ffi As VS_FIXEDFILEINFO
- Dim fiiaddr&
- #If Win32 Then
- Dim fiilen&
- Dim di&
- #Else
- Dim fiilen%
- Dim di%
- #End If
- Dim res$, crlf$
- crlf$ = Chr$(13) + Chr$(10)
- If UBound(verbuf) <= 1 Then
- MsgBox "No version information available for this file"
- Exit Sub
- End If
- di = VerQueryValue(verbuf(0), "\", fiiaddr&, fiilen)
- If di = 0 Then
- MsgBox "No fixed version information in this file"
- Exit Sub
- End If
- ' Copy the fixed file info into the structure
- agCopyData ByVal fiiaddr&, ffi, 52
- ' Now build the output report
- res$ = "File Version " + CalcVersion$(ffi.dwFileVersionMS) + "." + CalcVersion$(ffi.dwFileVersionLS) + crlf$
- res$ = res$ + "Product Version " + CalcVersion$(ffi.dwProductVersionMS) + crlf$
- res$ = res$ + "File type is: "
- Select Case ffi.dwFileType
- Case VFT_UNKNOWN
- res$ = res$ + "unknown"
- Case VFT_APP
- res$ = res$ + "application"
- Case VFT_DLL
- res$ = res$ + "dynamic link library"
- Case VFT_DRV
- res$ = res$ + "device driver"
- Case VFT_FONT
- res$ = res$ + "Font resource"
- Case VFT_VXD
- res$ = res$ + "virtual device"
- Case VFT_STATIC_LIB
- res$ = res$ + "static link library"
- End Select
- res$ = res$ + crlf$
- MsgBox res$, 0, "Fixed Version Info"
- End Sub
- Private Sub ShowPrinters()
- #If Win32 Then
- Dim ft As FILETIME
- Dim keyhandle&
- Dim res&
- Dim curidx&
- Dim keyname$, classname$
- Dim keylen&, classlen&
- Dim msg$
- Dim reserved&
- res& = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SYSTEM\CurrentControlSet\Control\Print\Printers", 0, KEY_READ, keyhandle)
- If res <> ERROR_SUCCESS Then
- MsgBox "Can't open key"
- Exit Sub
- End If
- Do
- keylen& = 2000
- classlen& = 2000
- keyname$ = String$(keylen, 0)
- classname$ = String$(classlen, 0)
- res = RegEnumKeyEx(keyhandle, curidx, keyname$, keylen, reserved, classname$, classlen, ft)
- curidx = curidx + 1
- If res = ERROR_SUCCESS Then msg$ = msg$ & Left$(keyname$, keylen) + vbCrLf
- Loop While res = ERROR_SUCCESS
- Call RegCloseKey(keyhandle)
- MsgBox msg$, 0, "Printers"
- #Else
- MsgBox "This function is not supported under Win16 in this example."
- #End If
- End Sub
-