Board index » delphi » example for loading picture from DLL

example for loading picture from DLL


2005-10-18 12:07:13 AM
delphi21
Hello,
I have a lot a picture to include in a wizard.
I would like to include them in a external DLL, if possible in Jpeg.
Anyone have a sample of how to do this kind of stuff?
thanks
John
 
 

Re:example for loading picture from DLL

In article <XXXX@XXXXX.COM>, John writes:
Quote
I have a lot a picture to include in a wizard.
I would like to include them in a external DLL, if possible in Jpeg.

Anyone have a sample of how to do this kind of stuff?
You can put any kind of files into RCDATA resources. Start by creating
a new DLL project in the IDE. Add new textfile to the project, save it
as, say, JPegs.RC.
Add lines to it like
IMAGE1 RCDATA "image1.jpg"
IMAGE2 RCDATA "image2.jpg"
If you use filenames only the files have to sit in the same folder the
RC file is in, but you can use full pathes as well.
Leave the DPR file as it is (no added code), save the project and build
it. This gives you a DLL that basically contains no code (with the
exception of the RTL initialization, which you cannot remove easily).
To use the images in this DLL you load it first using
hImageDLL := LoadLibraryEx( PChar(FullPathnameOfDLL), 0,
LOAD_LIBRARY_AS_DATAFILE );
if hImageDLL = 0 then
RaiseLastOSError;
Loading the DLL this way executes no code in it.
Having the DLLs module handle you can get at the images by using a
TResourceStream:
rs := TResourceStream.Create( HImageDLL, 'IMAGE1', RT_RCDATA );
try
aJpegImage.LoadFromStream(rs);
finally
rs.Free;
end;
Types used are
hImageDLL: THAndle; // or HMODULE
rs : TResourceStream;
aJpegImage: TJpegImage;
The sample above assumes that aJpegImage was created elsewhere, of
course.
Peter Below (TeamB)
Use the newsgroup archives :
www.mers.com/searchsite.html
www.tamaracka.com/search.htm
groups.google.com
www.prolix.be
 

Re:example for loading picture from DLL

Thanks Peter.