Loading Custom Resources

I want to load custom resources into a TMemoryStream. I have made a *.RES file with custom data types (using Borland Workshop).  But my app keeps saying "Resource not found error". I am trying to load it with the command

FCompressedStream := TResourceStream.Create(HInstance, ResName, RT_RCDATA);

---------------------
Extra info
---------------------
I'm using D3 and Win95.

The custom resource happens to be a compressed bitmap. (Yes, I really really do want to compress it - it makes my EXE infinitly smaller and then I decompress it once only at run time).
WarrenYoungEdinburghAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
JimBob091197Connect With a Mentor Commented:
Glad it worked.  I assume that I can answer the question then?

JB
0
 
ZifNabCommented:
Hi,

have you added the following in the compiler directive in the implementation
               section of your unit. {$R ResourceFilename} ?

Regards, zif.

0
 
WarrenYoungEdinburghAuthor Commented:
Yes I have added that, with the .res on the end of the filename.
0
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
WarrenYoungEdinburghAuthor Commented:
Judging from the size of the EXE file, it is clear that the resource file is being included in the EXE.
0
 
ZifNabCommented:
strange,

What about ...., PCHAR(RT_RCDATA);
0
 
JimBob091197Commented:
Try also:
  MyResStr := TResourceStream.Create(hInstance, PChar('#123'), PChar('MYSECTION'));
where MYSECTION is the resource group that you have put your resource 123 in.

I wrote the following function, and have used it several times to save a resource to disk:

function ExtractFileFromRes(hLib: Integer; const Filename, ResType, ResName: string): Boolean;
// E.g. ExtractFileFromRes(hInstance, 'C:\Test.exe', 'CUSTOM', '#123');
var
  rs: TResourceStream;
begin
  Result := True;
  try
    rs := TResourceStream.Create(hLib, PChar(ResName), PChar(ResType));
    try
      rs.SaveToFile(Filename);
    finally
      rs.Free;
    end;
  except
    Result := False;
  end;
end;

JB
0
 
WarrenYoungEdinburghAuthor Commented:
Thank you Jim Bob. That solved it. The trick was how to utilise a custom resource type.

Thanks very much.
Warren.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.