How to create and use a resource-only DLL (Views: 100)
How do I create a DLL with just graphics files, then allow several different DLL's and applications to use these files?
First, create a resource source file (*.RC) containing references to the bitmaps:
CLOSEBUTTON BITMAP "C:\Projects\closebtn.bmp"
OPENBUTTON BITMAP "C:\Projects\openbtn.bmp"
This is just an ordinary text file, so you can use the Delphi code editor or any other text editor to create it. Make sure the names of the bitmaps (CLOSEBUTTON, etc.) are ALL UPPERCASE.
Next, compile this .RC file to create the corresponding .RES file, using BRCC32.EXE:
Now start a new DLL project in Delphi and link the .RES file into it with an $R directive:
Compile this code, and you now have a resource DLL containing the bitmaps.
To use these resources in an EXE or another DLL, you need to use LoadLibrary to get a handle to the DLL, and then LoadBitmap to get a handle to the bitmap:
DllHandle := LoadLibrary('MyImages.dll');
if DllHandle <> 0 then
CloseButtonBmp := TBitmap.Create;
CloseButtonBmp.Handle := LoadBitmap(DllHandle, 'CLOSEBUTTON');
OpenButtonBmp := TBitmap.Create;
OpenButtonBmp.Handle := LoadBitmap(DllHandle, 'OPENBUTTON');
Once you've loaded the bitmaps, you can assign them to their final destinations, wherever that may be, and then free them.
<< Back to main page