I get some exceptions when I read the file info from some applications and the method I am using is provided by Lazarus.Please, give a link to the "some applications" exe file (without setup), for testing.
Please, give a link to the "some applications" exe file (without setup), for testing.
I posted the names of some of these applications (Firefox, System Explorer, etc) in my first posting.Oops, missed FireFox.
Is this a fix that will be included in Lazarus in the future?Given the cross-platform nature of the FPC, it is very doubtful. Just use it in your project.
Given the cross-platform nature of the FPC, it is very doubtful. Just use it in your project.
@ASergeProblem in Acronis True Image.
But one user reported that he gets no information when he tries to read them from the application Acronis True Image Home.
Can you please try your code with this EXE and tell me where the problem might be?
Problem in Acronis True Image.
There is it's VersionInfo block:As you can see VarFileInfo=0x0000 0x04B0, but StringFileInfo contains only "040904b0", and the block "000004b0" does not. This is a mistake of developers of acronis.
1 VERSIONINFO FILEVERSION 22,5,1,12510 PRODUCTVERSION 22,5,1,12510 FILEOS 0x4 FILETYPE 0x1 { BLOCK "StringFileInfo" { BLOCK "040904b0" { VALUE "Comments", "http://www.acronis.com/" VALUE "CompanyName", "Acronis International GmbH" VALUE "FileDescription", "Acronis True Image 2018" VALUE "FileVersion", "22,5,1,12510" VALUE "InternalName", "ti_console" VALUE "LegalCopyright", "Copyright (C) Acronis International GmbH, 2002-2017." VALUE "LegalTrademarks", "Acronis International GmbH. All rights reserved." VALUE "OriginalFilename", "ti_console.exe" VALUE "ProductName", "Acronis True Image 2018" VALUE "ProductVersion", "22,5,1,12510" } } BLOCK "VarFileInfo" { VALUE "Translation", 0x0000 0x04B0 } }
Where can this version-information that you postet be found?From documentation https://docs.microsoft.com/en-us/windows/desktop/menurc/versioninfo-resource (https://docs.microsoft.com/en-us/windows/desktop/menurc/versioninfo-resource)
What do thoese Hex-Values (like 0x0000) mean?
But is this a universal working code (for all applications that have the same issues in the version info)?This is a fix for errors such as those in Acronis True Image. In normal cases, this is not necessary. Applications are usually developed without taking into account other developers errors, but if the percentage of such errors is large, then add code that takes this into account.
Or is this just a fix for Acronis True Image?
There are sometimes differences between File Version (from first code) and File Version (from second code).The link above already contains information. These fields are different. A string is a general way of storing data for a version resource, and a numeric one is a dedicated way of storing data for quick access (For example the SysUtils.GetFileVersion reads it). Usually developers make them the same.
If the function fails, the return value is zero. To get extended error information, call GetLastError.
The most probable cause for the function to fail is that the executable has no version info but there are others: You should check the error info and act in consequence.Which it doesn't properly. Right? It should only raise if there is actually an error.
According to Microsoft's doc (https://docs.microsoft.com/en-us/windows/desktop/api/winver/nf-winver-getfileversioninfosizew):QuoteIf the function fails, the return value is zero. To get extended error information, call GetLastError.
The most probable cause for the function to fail is that the executable has no version info but there are others: You should check the error info and act in consequence.
I am not a good programmer, what must be changed in ReadVersionInfo?Nothing.
When I select an application that causes problems I see the error message (as expected).
But I also get an Access-Violation message.
So maybe I have to add the try block in TVersionInfo.ReadVersionInfo ?
Or should I modify TVersionInfo.ReadVersionInfo so when the size is zero, that I don't call RaiseLastOSError but show a message and exit?
I added a try ... except block:Bad code: release object not in finally, but in the except block. When an exception occurs, the constructor calls the destructor and then you use Free again.
try // Create the Version Information VerInfo := TVersionInfo.Create(AppFileName); except // will only be executed in case of an exception on E: Exception do begin ShowMessage( 'Error: '+ E.ClassName + #13#10 + E.Message ); VerInfo.Free; exit; end; end;
When I select an application that causes problems I see the error message (as expected).
But I also get an Access-Violation message.
Bad code: release object not in finally, but in the except block. When an exception occurs, the constructor calls the destructor and then you use Free again.
Use right construction:
try VerInfo := TVersionInfo.Create(AppFileName); try // Do something with version finally VerInfo.Free; end; except on E: Exception do ShowMessage( 'Error: '+ E.Message); end;