MusicLoad and custom resources

Started by Anders2,

Anders2

This should be an easy one for you guys....
It's almost embarassing to post this  :)

I've loaded a MOD as a custom resource with the name
IDR_MUSIC but get a undefined identifier error on the resource with this code snippet:

mod=BASS_MusicLoad (TRUE,IDR_MUSIC,0,BASS_MUSIC_LOOP);

I can double click the resource in resource view to open the MOD so that part seems ok. Seems like I missed something
with the resource since it's not recognized. In the resource.h file IDR_MUSIC have a number defined. Can anyone explain what I have missed?

DanaPaul

I don't see any Resource.h file in the MS SDK, and I'm not aware of any BASS resource file functionality, so I'll offer a generic answer...

Generally speaking, you need to load custom resources into memory from your executable file before you can use it.  Usually, custom resources are stored in the resource file as a "RawData" resource type.

Whenever I've embedded WAVE files into a resource file I usually store 2 important references specific to the resource itself.  A unique resource identifier, and the size of the (Wave file) resource.

You need to know the size of the resource to read the (Wave file) bytes loaded into memory after using API function "LoadResource."

Once the resource is loaded into memory you can pass the memory pointer result to a function that accesses memory streams or write these bytes to disk and pass the file name to functions that access file streams.

Anders2

Ah, maybe I'm a bit unclear here. The resource.h is created in Visual Studio when you add a resource, its not part of the SDK. What I am trying to do, is to include a module in my EXE file, just as you can add a BMP. When the file is added it gets a tag for access, in this case IDR_MUSIC. (If you add a BMP I think it gets a IDB_BITMAP1 or similiar).

So the custom resources in this case are stored within the EXE file, and "resource handling" is a Visual Studio thing in this case.

But since I am a beginner in the Win and Visual Studio area, I am not certain that this is done correctly.
Can a module be stored and accessed this way, or do I have to read it from file to a memory location before the call?

DanaPaul


Quoteor do I have to read it from file to a memory location before the call?

Bingo!

You cannot pass the resource variable to BASS.  Other API functions may support resource files, but BASS isn't looking for a resource identifier in it's own parameter lists.

Nice idea though :)

WingZero

 You would use LoadResource() to get a handle to the resource. Then you would use LockResource() to get the pointer to the resource data. You can use SizeofResource() to get the size.

DanaPaul


QuoteYou can use SizeofResource() to get the size.

SizeOfResource returns the amount of memory allocated for the resource.  Not the byte count of the original resource data.  Memory allocated for a resourceof any type is usually a minimum of 64Kb and usually in increments of 64Kb.  If memory serves me well I believe the granularity of this allocated memory is dependent on memory paging size.