Solved

Loading Custom Resources

Posted on 1998-03-04
7
163 Views
Last Modified: 2010-04-06
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).
0
Comment
Question by:WarrenYoungEdinburgh
  • 3
  • 2
  • 2
7 Comments
 
LVL 8

Expert Comment

by:ZifNab
ID: 1360075
Hi,

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

Regards, zif.

0
 

Author Comment

by:WarrenYoungEdinburgh
ID: 1360076
Yes I have added that, with the .res on the end of the filename.
0
 

Author Comment

by:WarrenYoungEdinburgh
ID: 1360077
Judging from the size of the EXE file, it is clear that the resource file is being included in the EXE.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 8

Expert Comment

by:ZifNab
ID: 1360078
strange,

What about ...., PCHAR(RT_RCDATA);
0
 
LVL 5

Expert Comment

by:JimBob091197
ID: 1360079
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
 

Author Comment

by:WarrenYoungEdinburgh
ID: 1360080
Thank you Jim Bob. That solved it. The trick was how to utilise a custom resource type.

Thanks very much.
Warren.
0
 
LVL 5

Accepted Solution

by:
JimBob091197 earned 100 total points
ID: 1360081
Glad it worked.  I assume that I can answer the question then?

JB
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

713 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question