'获取文件信息
'Lx 类别
'=0 获取文件版本号
'=1
'=2
'=3
'=4
'=5
Function GetVersionInfo(ByVal FileName as String, ByVal Lx as Integer = 0) as String
   '获取文件版本号
   Dim as UInteger rc,lBufferLen,lVerPointer,lVerbufferLen,aa,bb
   Dim sBuffer() as Byte
   Dim udtVerBuffer as VS_FIXEDFILEINFO
   Dim ss as ZString * 1024
   ss = FileName
   lBufferLen = GetFileVersionInfoSizeA(@ss, Null)
   
   If lBufferLen < 1 Then
      'Print "该文件没有版本信息!"
      Exit Function
   End If
   '**** Store info to udtVerBuffer struct ****
   ReDim sBuffer(lBufferLen)
   rc = GetFileVersionInfoA(@ss, 0, lBufferLen, @sBuffer(0))
   If rc Then
      rc = VerQueryValueA(@sBuffer(0), "\", CPtr(LPVOID Ptr, @lVerPointer), Cast(PUINT, @lVerbufferLen))
      
      If rc Then
         rc = SizeOf(VS_FIXEDFILEINFO)
         memcpy @udtVerBuffer, Cast(Any Ptr, lVerPointer), rc
         Select Case lx
            Case 0 '获取版本
               'aa=Cast(Integer,@udtVerBuffer.dwFileVersionMS)
               'bb=Cast(Integer,@udtVerBuffer.dwFileVersionLS)
               'Function=Peek(Short,aa+2) & "."  & Peek(Short,aa) & "."  & Peek(Short,bb+2) & "."  & Peek(Short,bb)
               Function = HiWord(udtVerBuffer.dwFileVersionMS) & "." & _
                  LoWord(udtVerBuffer.dwFileVersionMS) & "." & _
                  HiWord(udtVerBuffer.dwFileVersionLS) & "." & _
                  LoWord(udtVerBuffer.dwFileVersionLS)
         End Select
      End If
   End If
   'Print "dwSignature=" & udtVerBuffer.dwSignature
   'Print "dwStrucVersion=" & udtVerBuffer.dwStrucVersion
   'Print "dwFileVersionMS=" & udtVerBuffer.dwFileVersionMS
   'Print "dwFileVersionLS=" & udtVerBuffer.dwFileVersionLS
   'Print "dwProductVersionMS=" & udtVerBuffer.dwProductVersionMS
   'Print "dwProductVersionLS=" & udtVerBuffer.dwProductVersionLS
   'Print "dwFileFlagsMask=" & udtVerBuffer.dwFileFlagsMask
   'Print "dwFileFlags=" & udtVerBuffer.dwFileFlags
   'Print "dwFileOS=" & udtVerBuffer.dwFileOS
   'Print "dwFileType=" & udtVerBuffer.dwFileType
   'Print "dwFileSubtype=" & udtVerBuffer.dwFileSubtype
   'Print "dwFileDateMS=" & udtVerBuffer.dwFileDateMS
   'Print "dwFileDateLS=" & udtVerBuffer.dwFileDateLS
   
   'Type tagVS_FIXEDFILEINFO
   'dwSignature as DWORD
   'dwStrucVersion as DWORD
   'dwFileVersionMS as DWORD
   'dwFileVersionLS as DWORD
   'dwProductVersionMS as DWORD
   'dwProductVersionLS as DWORD
   'dwFileFlagsMask as DWORD
   'dwFileFlags as DWORD
   'dwFileOS as DWORD
   'dwFileType as DWORD
   'dwFileSubtype as DWORD
   'dwFileDateMS as DWORD
   'dwFileDateLS as DWORD
   'End Type
End Function
