PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Resources, again - help pelase @:-)

HI all, Ive tried at add resources to my program, with some luck, I did add a tga, but it appeared upside down, anyhow, I'd like to add a .IT (music file), and have added it as a resource, and fron the resource.h file I can see that it is the following:

#define IDR_BINARY1 105

I then tried to use mikmod to load the resource using a func posted in another thread (refractor I think):
Code:


//
// FUNCTION: moveGetRawResourcePointer()
//
// PURPOSE: Returns a pointer to a TGA file in the resource file.
//
// COMMENTS:
//
// Returns a pointer to a TGA file in the resource file. Note that the memory
// taken by the LoadResource function has to be freed by the calling function.
//
unsigned short * moveGetRawResourcePointer( LPCTSTR lpResourceName )
{
// Find the resource in this module.
HRSRC hRsrc = FindResource( GetModuleHandle(NULL), lpResourceName, TEXT("BINARY") );
if( hRsrc == NULL )
return NULL;

// Load the resource into memory and get a pointer to the memory location.
HGLOBAL hGlobal = LoadResource( GetModuleHandle(NULL), hRsrc );
if( hGlobal == NULL )
return NULL;

return (unsigned short *)hGlobal;
}



Player_Load(moveGetRawResourcePointer(MAKEINTRESOURCE(IDR_BINARY1)),8,0);


anyway it compiles... then just crashes... any ideas? or better ways to do it?
Using the Player_Load() func return the following error: cannot convert parameter 1 from 'unsigned short *' to 'char *'

-surly someone has done this?
BTW, twas me..... did not login "DOH"! @:-)
Conan · 13 Jun 2002, 07:38 UTC — Hi Brendan
We are going through the same learning curve you & I. I'm using string table resources & making similar mistakes.

I guess the answer is in what you are trying to pass the resource item to. It wants an int ponter & you are giving it a char pointer & the conversion won't work.

After trying everything I could think of to solve my loadstring issue I went looking through the supplied sample projects & on examining one discovered that what I thought was a bug with the way I was defining a string was actually to do with the way I was defining the length of the string.

If you have not solved this yet let me know & I will duplicate & assist
Not yet, no matter what I do it just crashes....

I'm looking into the diffs between the Player_Load and Player_LoadFP.... too see what the diffs are etc.

-Brendan
Try changing line 23 to:
Code:

return (unsigned short *)LockResource(hGlobal);

Dan East
Sorry, no luck there Dan....

according to the .h file for mikmod:

Code:

MIKMODAPI extern MODULE* Player_Load(CHAR*,int,BOOL);
MIKMODAPI extern MODULE* Player_LoadFP(FILE*,int,BOOL);


the int is to define the number of tracks the module can use, the bool is the "The curiosity level to use."

-anyhow any more Ideas would be good....

After looking at the doco, I think I'm calling the func with the wrong stuff... i.e it assumes its a filename to load....

the Player_LoadFP states that the file* is:
"An open file, at the position where the module starts. "

-Thanks
I see the problem. Player_Load only supports reading from an actual file. I can think of two solutions. First, you can dump the resource to a temp file, then have MikMod load that file. It would only take a couple lines of code to implement that, and you could delete the file after you are done playing the mod. The other is to take a deeper look at the MikMod library, and either modify it to load directly from a resource, or see if you can pass it a raw chunk of memory and load from that stream instead of opening a file stream. The latter is what you are actually trying to do if you use the last suggestion I posted.

Dan East
don't like the temp idea, as files tend to hang around if program crashes.... :) Might have to look at the load code... or just say "stuff it", and supply files sepratly.... as files... ;) (only problem with that is makes it easy for others to hack around with program....

-Brendan