Author Topic: Bundling to the extreme  (Read 2254 times)

Bonko

  • Posts: 1
Bundling to the extreme
« on: 19 Jan '03 - 17:00 »
Hi kids. I think the most common question regarding bassmod, and especially demo coding in general, is how to stick stuff into the exe and then use it in the program. So i thought i would post a little step by step guide to bundling modules. If this is old news for you, you may click away. If not, open a can of Dr pepper and read on.


Step one (un burro).
First of all you need to, or atlest it helps, write a resource script. Open up your favorite text-editor, which we can assume will be notepad, and write the following:
Code: [Select]

100 RCDATA module.xm

The number is just an identifier and can be set to anything, atleast as long as the value is not higher than a kite.

Save the text as RES.RC


Step two (dos burros).
Put module.xm and RES.RC in the same directory. Or include a path in your resource script.
Then obtain a resource compiler, usually one comes with the environment package. If you have none, or prefer easy methods, you could download Resource Builder 1.0 from http://www.sicomponents.com/download.html. Personally, i prefer borlands BRC32.EXE. If we assume you do the same, you would type the following:
Code: [Select]
brc32 -r RES.RC -fo RES.RES
The switch -r is not used in later builds of BRC32, but it's still there for completion. -fo is not required, but it is used to specify a filename for the resource.


Step three (tres burros).
Now we have the compiled resource, RES.RES. Put it in the source-directory of your program, there are severeal ways to include a resource in your program. One way is to simply include it into the project, Project - add to project. I prefer doing it this way, add this line to the top of your source.
Code: [Select]
#pragma resource "RES.RES"
That tells the compiler to include the resource. It is not exactly standard, but works in most later environments.

The next time you build your program, you will see an increase in filesize which indicates that the resource has bee included. Now we just need to utilize it.


Step four (cuatro burros).
There are a few ways to tell the code to deal with the resources, this function is pretty tidy and does what it should..
Code: [Select]

UCHAR* read_resource(int id) {
HRSRC rsrc = FindResource(HInstance, MAKEINTRESOURCE(id),RT_RCDATA);
HGLOBAL global = LoadResource(HInstance,rsrc);
return ((UCHAR*)LockResource(global)); }

As you probably see, this code is for C. But it is quite easy to convert since dealing with resources is standard.
What it does is pretty self-explanitory. Locates, reads and returns. Declare if needed. The only thing you might need to change is
HInstance. If something complains, change to whatever your WINAPI uses. Or if you are feeling lucky, punk, just write NULL.


Step five (cinco burros).
Since BASSmod supports reading from memory, dealing with the moduleresource will be a breeze. Assuming that you have already initialized a sound device, simply use this line:
Code: [Select]

BASSMOD_MusicLoad(TRUE,read_resource(100),0,0,BASS_MUSIC_RAMPS);



That's pretty much it. After your program has compiled, you might want to use UPX.EXE (http://upx.sourceforge.net/) to shrink the final size. Next time, boys and girls, if needed, we might deal with the bundling of runtime files.
« Last Edit: 19 Jan '03 - 17:38 by Bonko »