Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Storing jpegs inside dll?

Status
Not open for further replies.

KempCGDR

Programmer
Jan 10, 2003
445
GB
Hi, I want to store jpegs inside a DLL so my program can retrieve them, obviously it's possible to do this because various places have mentioned it (eg for program skins), but I can't find out how. Assuming there is a way, can they be identified with the equivalent of filenames?

Thanks in advance.
 
Later today I'll post a sample I don't have at hand now. The images can be retrieved by Resource-ID.

Later,
TonHu
 
Here's some code to load a jpg file from a dll, that was compiled with brcc32.exe and dcc32.exe by Borland. Those exe's should be installed in your Delphi\bin direcory.

Code:
Var Res : TResourceStream;
ReklameID : LongWord; // or THandle
ReklameNu : Integer;
...
ReklameID := LoadLibrary('.\Reklame'); // load resource-dll
ReklameNu := 100; // or 101, determined by .rc file
...
If ReklameID <> 0 then
Begin
Res := TResourceStream.CreateFromID(ReklameID,
         ReklameNu,RT_RCDATA);  // picture
Try
    Picture.Graphic := JPeg.TJPegImage.Create;
    Picture.Graphic.LoadFromStream(Res);
Finally
    Res.Free;
End;
End;

And my batchfile/brcc32 script/Delphi DLL project look like:

Code:
Batchfile: reklame.bat
<----include after this line---->
@Echo off
Echo Compile reklame-resource and DLL
brcc32 Reklame.rc
if errorlevel 1 goto Error
dcc32 -m Reklame.dpr
If errorlevel 1 goto Error
Echo Done.
Goto Einde
:Error
Echo ERROR!!!
:Einde
<----do not include this line---->

brcc32-file: Reklame.rc
<----include after this line---->
100 RCDATA &quot;Logo.jpg&quot;
101 RCDATA &quot;Company.jpg&quot;
<----do not include this line---->
You can add more files with unique ID's if you like

Delphi-reklame-project: Reklame.dpr
<----include after this line---->
Library Reklame;

{$R *.RES}
{$R Reklame.res}

Begin
End.
<----do not include this line---->
[code]

That should give you an idea to get things started.
My original source was more complex as I also get size and filetype parameters from the DLL, which are stored inside a stringtable. s-)

HTH
TonHu
 
Ok, I get all that, and I can make it work. Thanks. Will get back to you if I come up against any problems I can't solve retrieving them in my program.
 
Ok, I can't load it from my program as I have no idea where to start. I've tried all the help topics I can find about resource files and DLLs, but no luck. Might be because I'm running D3, got D7 on my other comp that I don't use anymore, but was off a shareware disc I borrowed and I won't see the person again to borrow again to install on here :(

The code I'm using to load from files at the moment is

JPEGIn := TJPEGImage.Create;
JPEGIn.LoadFromFile(Filename);
img.Picture.Assign(JPEGIn);
JPEGIn.Free;

Can I do a simple modification of this, or is it a rewrite?

Also, I'm thinking of storing a string table in the DLL storing the ID of the pic and its original filename (my program needs to know what pictures are available and they aren't guaranteed to have the same ID or be there at all between revisions). Would this be feasible?

Anyway, if you can tell me how to load something from the DLL then I should be able to figure out the rest myself. *crosses fingers*
 
You know what, I'm an idiot. Missed your code above, somehow. *Smacks brain into order*
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top