Recent

Author Topic: Issues with resourcecompiler  (Read 2500 times)

paulvanderlinden

  • New Member
  • *
  • Posts: 14
Issues with resourcecompiler
« on: February 15, 2023, 12:26:45 pm »
Hi,

I'm seeing some differences between delphi's resource compiler and fpcres on windows.
In delphi all values need to be terminated by a \0. if not you'll get some alignement issues like the fileprops attachment.
But when compiling in lazarus/freepascal, if the values are ending in \0 you'll get errors when using TVersionInfo.Load, it's complaining about duplicate keys:
Quote
An unhandled exception occurred at $004269B8:
EDuplicateKeyException: Duplicate key 'gramnam'
  $004269B8
  $00427535
  $0042701F
  $0040173C  main,  line 9 of project1.lpr

Any ideas on how to make the version.rc file work both in delphi and in fpc environments?

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12764
  • FPC developer.
Re: Issues with resourcecompiler
« Reply #1 on: February 15, 2023, 12:49:12 pm »
Maybe you also have the version info turned on in the project? That would maybe result in duplicates.

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2269
  • Fifty shades of code.
    • Delphi & FreePascal
Re: Issues with resourcecompiler
« Reply #2 on: February 15, 2023, 12:51:29 pm »
Code: Pascal  [Select][+][-]
  1. IDR_VERSION1 VERSIONINFO
  2. FILEVERSION 1,0,0,0
  3. PRODUCTVERSION 1,0,0,0
  4. FILEOS 0x00000004
  5. FILETYPE 0x00000001
  6. BEGIN
  7.   BLOCK "StringFileInfo"
  8.   BEGIN
  9.     BLOCK "00000000"
  10.     BEGIN
  11.       VALUE "FileVersion", "1.0.0.0\0"
  12.       VALUE "ProductVersion", "1.0.0.0\0"
  13.       VALUE "CompanyName", "KodeZwerg\0"
  14.       VALUE "FileDescription", "Cool app\0"
  15.       VALUE "InternalName", "VersionResourceExample\0"
  16.       VALUE "LegalCopyright", "2023 by KodeZwerg\0"
  17.       VALUE "LegalTrademarks", "\0"
  18.       VALUE "OriginalFilename", "App.exe\0"
  19.       VALUE "ProductName", "Appgasm\0"
  20.     END
  21.   END
  22.   BLOCK "VarFileInfo"
  23.   BEGIN
  24.     VALUE "Translation", 0x0000, 0x0000
  25.   END
  26. END
Save that as version.rc
in your file do {$R version.rc} and "Build".
works for any resource compiler same good.
« Last Edit: February 15, 2023, 12:54:28 pm by KodeZwerg »
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

paulvanderlinden

  • New Member
  • *
  • Posts: 14
Re: Issues with resourcecompiler
« Reply #3 on: February 15, 2023, 01:25:51 pm »
@marcov: no I don't have info in the project itself.
Judging from the cutoff name (gramnam) it seems like an alignment issue in the res file

And as for the working sample:
I think the only way this doesn't give an error when using TVersionInfo.Load is that there are no clashes in the misaligned parsed keys in that sample.
Keeping the same format but replacing it with my values does give that error about duplicate key.

Also: including .rc files in my dpr/lpr: delphi complaints and lazarus/fpc has the same issue as when including the (fpcres'd) .res file

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2269
  • Fifty shades of code.
    • Delphi & FreePascal
Re: Issues with resourcecompiler
« Reply #4 on: February 15, 2023, 01:52:11 pm »
I do compile my "non-IDE'd versioning" since ages on Delphi like my sample from above without getting any error.
I admit that I have no idea what "TVersionInfo" is since to include a rc/res file it is not needed.
To me it sounds like you having a bug somewhere since on my machine it works as predicted and shown.

Can you attach a demo project to check out if its a local problem at your side?
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

paulvanderlinden

  • New Member
  • *
  • Posts: 14
Re: Issues with resourcecompiler
« Reply #5 on: February 15, 2023, 01:56:13 pm »
That tversioninfo is so that I can read the properties (mainly fileversion) in the program itself, f.e. to show to the user.
like:
Code: Pascal  [Select][+][-]
  1. uses FileInfo,SysUtils;
  2. var v:TVersionInfo;
  3. begin
  4.   v := TVersionInfo.Create;
  5.   v.Load(HInstance);
  6.   writeln(Format('%d.%d.%d.%d',
  7.     [v.FixedInfo.FileVersion[0],
  8.      v.FixedInfo.FileVersion[1],
  9.      v.FixedInfo.FileVersion[2],
  10.      v.FixedInfo.FileVersion[3]
  11.     ]));
  12.   v.Free;
  13. end;
  14.  
That Load errors out due to alignment of the stuff from version.rc

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2269
  • Fifty shades of code.
    • Delphi & FreePascal
Re: Issues with resourcecompiler
« Reply #6 on: February 15, 2023, 02:45:33 pm »
I understand now and I have never used any pre-made solution to work with the WinAPI hand-in-hand so I can not judge them.
My own creation uses GetFileVersionInfoSizeA and GetFileVersionInfoA, since of that it never failed me.
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

paulvanderlinden

  • New Member
  • *
  • Posts: 14
Re: Issues with resourcecompiler
« Reply #7 on: February 15, 2023, 02:48:21 pm »
I did that too indeed in the delphi time.

But I also have to be able to run it on linux in the near future and that obviously have no support for the getfileversioninfo stuff as far as I could find

PascalDragon

  • Hero Member
  • *****
  • Posts: 6381
  • Compiler Developer
Re: Issues with resourcecompiler
« Reply #8 on: February 16, 2023, 07:23:36 am »
I'm seeing some differences between delphi's resource compiler and fpcres on windows.

It indeed seems that fpcres handles the \0 different from brcc as well as windres and gorc (the resource compilers FPC uses by default). For now I'd suggest you to simply use {$R version.rc}, then FPC will currently default to either windres or gorc depending on the platform, both of which handle this correctly.
For fpcres please file a bug report with a complete, but small and self contained example that shows this issue so that this isn't forgotten.

paulvanderlinden

  • New Member
  • *
  • Posts: 14
Re: Issues with resourcecompiler
« Reply #9 on: February 16, 2023, 03:39:26 pm »
https://gitlab.com/freepascal.org/fpc/source/-/issues/40152

but still: using {$R version.rc} does not compile in delphi and lazarus...

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12764
  • FPC developer.
Re: Issues with resourcecompiler
« Reply #10 on: February 28, 2026, 06:02:52 pm »
Resolved. It was not alignment, seems other resource compilers (rightfully) strip the terminating zero.

brcc32 goes a step further, and in some cases strips terminating zeroes altogether.

Thaddy

  • Hero Member
  • *****
  • Posts: 18911
  • Glad to be alive.
Re: Issues with resourcecompiler
« Reply #11 on: March 01, 2026, 06:33:19 pm »
https://gitlab.com/freepascal.org/fpc/source/-/issues/40152

but still: using {$R version.rc} does not compile in delphi and lazarus...
That only works for a complete build and the syntax is {$R version.res version.rc}
This will invoke the resource compiler in bothe Delphi and FPC, such that the rc is compiled and the resulting res is linked. But it needs a build, not just a compile.
Recovered from removal of tumor in tongue following tongue reconstruction with a part from my leg.

 

TinyPortal © 2005-2018