# 给一个简单的范例

Posted by Sephiroth on April 30, 1999 at 15:49:37:

In Reply to: 请问 VB 如何取得自己的版本编号，谢谢。 posted by 小游 on April 29, 1999 at 15:31:04:

给一个简单的范例(如下), 档案的版本资讯便是从 sBuffer() 这个 byte array 解读得到的.

Private Declare Function GetFileVersionInfo Lib "version.dll" Alias "GetFileVersionInfoA" ( _
ByVal lptstrFilename As String, _
ByVal dwHandle As Long, _
ByVal dwLen As Long, _
lpData As Any) As Long

Private Declare Function GetFileVersionInfoSize Lib "version.dll" Alias "GetFileVersionInfoSizeA" ( _
ByVal lptstrFilename As String, _
lpdwHandle As Long) As Long

Private Sub Form_Click()
Dim Buffer As String
Dim sFileName As String
Dim lReturn As Long
sFileName = "C:\Program Files\Microsoft Visual Studio\Vb98\Vb6.exe"
Dim lBufferLen As Long, lDummy As Long
lBufferLen = GetFileVersionInfoSize(sFileName, lDummy)
If lBufferLen < 1 Then
MsgBox "No Version Info available!"
Exit Sub
End If
Dim sBuffer() As Byte
ReDim sBuffer(lBufferLen)
lReturn = GetFileVersionInfo(sFileName, 0&, lBufferLen, sBuffer(0))
If lReturn = 0 Then
MsgBox "GetFileVersionInfo failed."
Exit Sub
End If
Dim sFileBuff As String
sFileBuff = sBuffer
Open "C:\Vb6" For Output As #1
Print #1, sFileBuff
Close #1
MsgBox "File Version Information was export to C:\Vb6"

End Sub

Follow Ups: