如何获取DLL的版本信息?

解决方案 »

  1.   

    和获取exe版本信息有区别吗?
      

  2.   

    如果Dll是你自己写的话,在Dll中创建一个输出函数,来返回你的Dll版本信息function GetVersionInfo: ShortString;  stdcall;
    const
      cVersionInfoStr='Ver1.0. 2010-06-22';
    begin
      Result:=cVersionInfoStr;
    end然后再到你的应用程序中调用它就行了,而每次你编译Dll时,手工修改GetVersion中的版本信息。
      

  3.   


    procedure GetVersionInfo(FFilePath: string);
    const
      SNotAvailable = 'Value Not Available';
    var
      LanguageID: string;
      CodePage: string;
      TranslationLength: Cardinal;
      TranslationTable: Pointer;
      InfoSize, Temp, Len: DWord;
      InfoBuf: Pointer;
      CompanyName, FileDescription, FileVersion, InternalName, LegalCopyright: string;
      LegalTradeMarks, OriginalFilename, ProductName, ProductVersion, Comments: string;
      Value: PChar;
      LookupString: string;
      PathStz: array[ 0..MAX_PATH ] of Char;
    begin
      // Get File Version Information
      if FFilePath = '' then
      begin
        GetModuleFileName( HInstance, PathStz, SizeOf( PathStz ) );
        FFilePath := StrPas( PathStz );
      end;
      InfoSize := GetFileVersionInfoSize( PChar( FFilePath ), Temp );
      if InfoSize > 0 then
      begin
        InfoBuf := AllocMem( InfoSize );
        try
          GetFileVersionInfo( PChar( FFilePath ), 0, InfoSize, InfoBuf );
          if VerQueryValue( InfoBuf, '\VarFileInfo\Translation', TranslationTable, TranslationLength ) then
          begin
            CodePage := Format( '%.4x', [ HiWord( PLongInt( TranslationTable )^ ) ] );
            LanguageID := Format( '%.4x', [ LoWord( PLongInt( TranslationTable )^ ) ] );
          end;      LookupString := 'StringFileInfo\' + LanguageID + CodePage + '\';      if VerQueryValue( InfoBuf, PChar( LookupString + 'CompanyName' ), Pointer( Value ), Len ) then
            CompanyName := Value;
          if VerQueryValue( InfoBuf, PChar( LookupString + 'FileDescription' ), Pointer( Value ), Len ) then
            FileDescription := Value;
          if VerQueryValue( InfoBuf, PChar( LookupString + 'FileVersion' ), Pointer( Value ), Len ) then
            FileVersion := Value;
          if VerQueryValue( InfoBuf, PChar( LookupString + 'InternalName' ), Pointer( Value ), Len ) then
            InternalName := Value;
          if VerQueryValue( InfoBuf, PChar( LookupString + 'LegalCopyright' ), Pointer( Value ), Len ) then
            LegalCopyright := Value;
          if VerQueryValue( InfoBuf, PChar( LookupString + 'LegalTrades' ), Pointer( Value ), Len ) then
            LegalTradeMarks := Value;
          if VerQueryValue( InfoBuf, PChar( LookupString + 'OriginalFilename' ), Pointer( Value ), Len ) then
            OriginalFilename := Value;
          if VerQueryValue( InfoBuf, PChar( LookupString + 'ProductName' ), Pointer( Value ), Len ) then
            ProductName := Value;
          if VerQueryValue( InfoBuf, PChar( LookupString + 'ProductVersion' ), Pointer( Value ), Len ) then
            ProductVersion := Value;
          if VerQueryValue( InfoBuf, PChar( LookupString + 'Comments' ), Pointer( Value ), Len ) then
            Comments := Value;
        finally
          FreeMem( InfoBuf, InfoSize );
        end;
      end
      else
      begin
        CompanyName := SNotAvailable;
        FileDescription := SNotAvailable;
        FileVersion := SNotAvailable;
        InternalName := SNotAvailable;
        LegalCopyright := SNotAvailable;
        LegalTrades := SNotAvailable;
        OriginalFilename := SNotAvailable;
        ProductName := SNotAvailable;
        ProductVersion := SNotAvailable;
        Comments := SNotAvailable;
      end;
      ShowMessage(CompanyName+ #13#10 + FileDescription + #13#10 + InternalName + #13#10 + FileVersion + #13#10 +
                  InternalName+#13#10 + LegalCopyright+#13#10 +LegalTrades+#13#10 +OriginalFilename+#13#10 +ProductName+#13#10
                  +ProductVersion+#13#10 +Comments);
    end;