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> &lt;Br/&gt; library project1; &lt;/P&gt; &lt;p&gt; {$ r&#39;res. res &#39;&#39;res. RC &#39;} &lt;/P&gt; &lt;p&gt; begin &lt;br/&gt; end. &lt;br/&gt; </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.
//: