Learn how to use resource files in [11]-DLL

Source: Internet
Author: User
Tags bmp image
In this example, a BMP image is embedded into the DLL as a source file, and then called.

Step 1: Create a DLL project ,:

Save the settings and use the default names here.

Step 2: Create a source file ,:

The Edit content is as follows (the file in the path must exist ):
Img1 bitmap "C: \ temp \ test.bmp"

Then, take a name (the suffix must be RC, And I will name it res. RC) and save it in the project directory.

Step 3: add the original resource file to the DLL project ,:

In this case, the source file {$ R 'res. res' res. RC '} will be added to the project source file. The source file we need is as follows:

<xmp> <Br/> library project1; </P> <p> {$ r'res. res ''res. RC '} </P> <p> begin <br/> end. <br/> </xmp>
Then press Ctrl + F9 to compile. At this time, the project 1.dll we need will be generated under the project directory.

Step 4: copy the project1.dll file to c: \ temp.
In this case, we can find this file through c: \ temp \ project1.dll. Now the DLL has been created.

Step 5: re-create a VCL Forms Application project, Code As follows:

 
Unit unit1; interfaceuses windows, messages, sysutils, variants, classes, graphics, controls, forms, dialogs; Type tform1 = Class (tform) Procedure formpaint (Sender: tobject); end; vaR form1: tform1; implementation {$ R *. DFM} procedure tform1.formpaint (Sender: tobject); var H: thandle; bit: tbitmap; begin H: = loadlibrary ('C: \ temp \ project1.dll '); {load DLL} bit: = tbitmap. create; bit. loadfromresourcename (H, 'img1'); {extract resource} canvas. draw (10, 10, bit); {draw an image on the form} freelibrary (h); {Load And Unload DLL} bit. free; end.

  //:


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.