Embedded Files

Is it possible to embed files into my VC++ project.

I’m writting a screensaver and I want to place all my media files (3do objects, textures, sounds, etc.) inside the SCR file. Is that possible?

Typically this is done by using resources files.

Look at the following API functions for info on how to read raw data from an embedded resource.


Embedding data with the EXE as resources is one way to store media. However in Win32 you cannot unload a resource as was possible in Win16. This means your screen saver will double its memory footprint.

For example:
let’s say all your media is 1MB and code is 50Kb. When the screen saver is activated 50Kb goes to the executable and a bit more goes to the heap and stack. When you load your resources another 1MB will be allocated. You’ll probably copy most as textures and verticies meaning your saver occupies another 1MB (either on the video card or on the heap). Since it is not possible to unload in Win32 total memory consumption is 2MB + 50Kb + a bit.

From a conservation stand point I’ve found it better to store all media in a separate resource only DLL. When you FreeLibrary the media DLL the original media gets dumped. This means memory consumption is 1MB + 50Kb + a bit. This goes against Microsoft guidelines on making screen savers but I don’t think they conceived of memory hungry screen savers when the guidelines were formulated.

If your media is small ignore what I’ve said.

My media is most likely going to be around 3-5 megs. I better start reading up on DLL files.

This is a newbie question, but I thought DLL only stores extra bits of code and not objects such as bitmaps, models, and such.

Embedded files in DLLs and EXEs can be anything. Anything means code, standard resource types (eg. bitmaps, menus, accel tables, string tables, icons, etc.) and non-standard data. Non-standard data might be 3D models, vertex arrays, texture coordinates, sound files or specially formated texture maps.

To add your non-standard data you would either load the .RC2 file as a text file and manually add the resources like this
1001 RCDATA c:\project\model.3ds
1002 RCDATA c:\project\boom.mp3

or type it in byte by byte like this
/* ahhhhh!!! */

or right click on the project’s resources and choose Import… (I haven’t tried it this way before). VC will suck in any files marked as RCDATA verbatim and treat them as raw binary.

When making a resource only DLL there is no code (hence the name) so you will have to manually add
to the project options edit box.

Good luck

[This message has been edited by Frumpy (edited 05-22-2001).]