Recent

Author Topic: [SOLVED] Error "Resource ... not found" using TResourceStream  (Read 6984 times)

Abelisto

  • Jr. Member
  • **
  • Posts: 91
[SOLVED] Error "Resource ... not found" using TResourceStream
« on: February 28, 2018, 04:47:09 pm »
It seems that I missed something very basic. I'v used this tutorial: http://wiki.freepascal.org/Lazarus_Resources#FPC_resources

This is my test code:

foo.pas
Code: Pascal  [Select][+][-]
  1. program foo;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. uses
  6.     Classes;
  7.  
  8. {$R foo.rc}
  9.  
  10. function foo(ModuleHandle : TFPResourceHMODULE; ResourceType, ResourceName : PChar; lParam : PtrInt) : LongBool; stdcall;
  11. begin
  12.     Writeln(ResourceName);
  13.     Result := true;
  14. end;
  15.  
  16. var
  17.     r: TResourceStream;
  18.     i: Byte;
  19. begin
  20.     {
  21.     for i := 1 to 24 do
  22.     begin
  23.         Writeln(i, ':');
  24.         EnumResourceNames(HINSTANCE, MAKEINTRESOURCE(i), @foo, 0);
  25.     end;
  26.     }
  27.     r := TResourceStream.Create(HINSTANCE, 'FOO', RT_RCDATA);
  28. end.

foo.rc
Code: Pascal  [Select][+][-]
  1. FOO RT_RCDATA "foo.pas"

And I got an error like:
Code: [Select]
An unhandled exception occurred at $00000000004270E6:
EResNotFound: Resource "FOO" not found

Looking into the binary I found that the data is presented.

What I missed?
« Last Edit: February 28, 2018, 06:41:50 pm by Abelisto »
OS: Linux Mint + MATE, Compiler: FPC trunk (yes, I am risky!), IDE: Lazarus trunk

rvk

  • Hero Member
  • *****
  • Posts: 6111
Re: Error "Resource ... not found" using TResourceStream
« Reply #1 on: February 28, 2018, 05:42:48 pm »
Does your example really compile for you????????  %)

(you could try 'RT_RCDATA')
« Last Edit: February 28, 2018, 05:46:01 pm by rvk »

Abelisto

  • Jr. Member
  • **
  • Posts: 91
Re: Error "Resource ... not found" using TResourceStream
« Reply #2 on: February 28, 2018, 06:41:23 pm »
Does your example really compile for you????????  %)

(you could try 'RT_RCDATA')

Yes, it is compilable.

And it seems that r := TResourceStream.Create(HINSTANCE, 'FOO', 'RT_RCDATA'); fixes the problem. Thanks a lot sir :)
OS: Linux Mint + MATE, Compiler: FPC trunk (yes, I am risky!), IDE: Lazarus trunk

rvk

  • Hero Member
  • *****
  • Posts: 6111
Re: Error "Resource ... not found" using TResourceStream
« Reply #3 on: February 28, 2018, 07:15:36 pm »
Yes, it is compilable.
How was that compilable?
In what unit is RT_RCDATA defined for you??

Is RT_RCDATA defined in Classes in an old version?

Abelisto

  • Jr. Member
  • **
  • Posts: 91
Re: Error "Resource ... not found" using TResourceStream
« Reply #4 on: February 28, 2018, 08:09:40 pm »
Yes, it is compilable.
How was that compilable?
In what unit is RT_RCDATA defined for you??

Is RT_RCDATA defined in Classes in an old version?

It is defined in the System unit, in the resh.inc file in particular: https://svn.freepascal.org/svn/fpc/trunk/rtl/inc/resh.inc
OS: Linux Mint + MATE, Compiler: FPC trunk (yes, I am risky!), IDE: Lazarus trunk

rvk

  • Hero Member
  • *****
  • Posts: 6111
Re: [SOLVED] Error "Resource ... not found" using TResourceStream
« Reply #5 on: February 28, 2018, 08:21:41 pm »
Ah, ok, that's why I didn't find it. It's NOT in system for Windows  :D

Code: Pascal  [Select][+][-]
  1. {$ifndef MSWINDOWS }
  2. { windows has this in the windows unit. It probably would better
  3.   fit into the classes/sysutils unit but because it is resource
  4.   related, I put it here (FK)
  5. }
  6. const
  7.   RT_CURSOR = MAKEINTRESOURCE(1);
  8.   RT_BITMAP = MAKEINTRESOURCE(2);
  9.   RT_ICON = MAKEINTRESOURCE(3);
  10.   RT_MENU = MAKEINTRESOURCE(4);
  11.   RT_DIALOG = MAKEINTRESOURCE(5);
  12.   RT_STRING = MAKEINTRESOURCE(6);
  13.   RT_FONTDIR = MAKEINTRESOURCE(7);
  14.   RT_FONT = MAKEINTRESOURCE(8);
  15.   RT_ACCELERATOR = MAKEINTRESOURCE(9);
  16.   RT_RCDATA = MAKEINTRESOURCE(10);
  17.   RT_MESSAGETABLE = MAKEINTRESOURCE(11);
  18.   RT_GROUP_CURSOR = MAKEINTRESOURCE(12);
  19.   RT_GROUP_ICON = MAKEINTRESOURCE(14);
  20.   RT_VERSION = MAKEINTRESOURCE(16);
  21.   RT_ANICURSOR = MAKEINTRESOURCE(21);
  22.   RT_ANIICON = MAKEINTRESOURCE(22);
  23.   RT_HTML = MAKEINTRESOURCE(23);
  24.   RT_MANIFEST = MAKEINTRESOURCE(24);
  25. {$endif MSWINDOWS }

 

TinyPortal © 2005-2018