Delphi 2010 resource File Usage

Source: Internet
Author: User

ProjectRecources... 
// 1 extract resources
procedure TForm1.Button1Click(Sender: TObject);
begin
  with  TResourceStream.Create(HInstance, ‘SnapShot_EXE‘, RT_RCDATA) do
  begin
     SavetoFile(‘SnapShot.exe‘);
     Free;
  end;
end;

// Play the wav file

// Use the icon file








Tresourcestream = Class (tcustommemorystream) Private hresinfo: thandle; hglobal: thandle; Procedure initialize (instance: thandle; Name, restype: pchar; fromid: Boolean); Public constructor create (instance: thandle; const resname: string; restype: pchar); constructor createfromid (instance: thandle; resid: integer; restype: pchar); destructor destroy; override; function write (const buffer; count: longint): longint; override; end;

Const
{Predefined resource types}
{$ Externalsym rt_cursor}
Rt_cursor = makeintresource (1); // cursor file
{$ Externalsym rt_bitmap}
Rt_bitmap = makeintresource (2); // bitmap
{$ Externalsym rt_icon}
Rt_icon = makeintresource (3); // icon
{$ Externalsym rt_menu}
Rt_menu = makeintresource (4 );
{$ Externalsym rt_dialog}
Rt_dialog = makeintresource (5 );
{$ Externalsym rt_string}
Rt_string = makeintresource (6 );
{$ Externalsym rt_fontdir}
Rt_fontdir = makeintresource (7 );
{$ Externalsym rt_font}
Rt_font = makeintresource (8 );
{$ Externalsym rt_accelerator}
Rt_accelerator = makeintresource (9 );
{$ Externalsym rt_rcdata}
Rt_rcdata = types. rt_rcdata; // makeintresource (10 );
{$ Externalsym rt_messagetable}
Rt_messagetable = makeintresource (11 );

Difference = 11;
{$ Externalsym difference}

Rt_group_cursor = makeintresource (DWORD (rt_cursor) + difference );
{$ Externalsym rt_group_cursor}
Rt_group_icon = makeintresource (DWORD (rt_icon) + difference );
{$ Externalsym rt_group_icon}
Rt_version = makeintresource (16 );
{$ Externalsym rt_version}
Rt_dlginclude = makeintresource (17 );
{$ Externalsym rt_dlginclude}
Rt_plugplay = makeintresource (19 );
{$ Externalsym rt_plugplay}
Rt_vxd = makeintresource (20 );
{$ Externalsym rt_vxd}
Rt_anicursor = makeintresource (21 );
{$ Externalsym rt_anicursor}
Rt_aniicon = makeintresource (22 );
{$ Externalsym rt_aniicon}
Rt_html = makeintresource (23 );
{$ Externalsym rt_html}
Rt_manifest = makeintresource (24 );






{Retrieve WAV resources}
WithTresourcestream. Create (hinstance, 'warning', rt_rcdata)Do
Begin
Savetofile('warning.wav ');
Free;
End;
 
// Package the EXE file into the resource file
I. Write RC Script text
Create a new notepad and enter exefile1 exefile "myexefile.exe" to save the file as exeres. RC.
2. Compile the RC file into a res resource file
 
Input in DOS
Brcc32 c: \ Users \ Administrator \ Desktop \ exeres. RC
// Copy brcc32.exe to the C: \ Windows directory in the delphix \ bin directory
 
3. Add source files to the Delphi Unit
Create a new project and copy the exeres. Res file to the project directory,
InImplementationIn {$ R *. DFM:
{$ R exeres. Res}
 
4. Extract the EXE file from the resource file uses classes;
ProcedureExtractres (restype, resname, resnewname:String);
VaR
Res: tresourcestream;
Begin
Res: = tresourcestream. Create (hinstance, resname, pchar (restype ));
Res. savetofile (resnewname );
Res. Free;
End;
 
// Extract the EXE file from the resource file
ProcedureTform1.button1click (Sender: tobject );
Begin
Extractres ('exfile', 'exefile1', 'c: \ Users \ Administrator \ Desktop \ aaa.exe ');
End;


From Weizhi note (wiz)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.