Forum > Windows

How do I determine the Version number of a DLL?

(1/1)

RedOctober:
Platform:  OS: Windows Server 2016    Lazarus 2.0.10   FPC   3.2.0
I'm working with several different versions of a DLL.  The file name is always the same.  I have a Windows app, with a main form, and I'd like to display the version number of the DLL in use, on the main form, in a Label.  I cannot find a function that can extract this information.

Does anyone know of a function or code snippet that can accomplish this?  Thanks in advance.

MarkMLl:
In the general case, can't be done. It would have to rely on the DLL author exporting a function (etc.) which declared the version number.

I've done quite a lot of custom hacking based on a DLL (or on Linux, shared object) exporting a magic number which defined the programming interface, but that relies on having full control of both the DLL and the program that's using it.

MarkMLl

trev:
See the Forum thread FileVersionInfo did not work with a DLL for the solution.

RedOctober:
Hi MarkMLI and Trev.  Thanks to your help, I was able to modify the code shown in the other examples, to determine the version of a single DLL, which is what I need. The code below works.



--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- uses  FileUtil, fileinfo, winpeimagereader; ... type  TDllInfo = class(TObject)    FileName : String;    ModulName : String;    Info : string;  end;  ...  function GetDLLVer(const dll_fnm: String): String; ... implementation  ...  function GetDLLVer(const dll_fnm: String): String;var  i: Integer;  FileVerInfo:TFileVersionInfo;  FileName, ModulName: String;  aDllInfo : TDllInfo;begin  FileVerInfo := nil;  try    FileVerInfo:= TFileVersionInfo.Create(nil);    FileVerInfo.FileName:= dll_fnm;    try      FileVerInfo.ReadFileInfo;      ModulName:= FileVerInfo.VersionStrings.Values['InternalName'];      if ModulName <> '' then begin        aDllInfo := TDllInfo.Create;        aDllInfo.FileName:= dll_fnm;        aDllInfo.ModulName:= ModulName;        aDllInfo.Info := FileVerInfo.VersionStrings.Values['FileVersion'];        Result := aDllInfo.Info;      end;    finally      ; // nothing to do    end;  finally    FileVerInfo.Free;  end;end;   

Navigation

[0] Message Index

Go to full version