0
0

Hi,
i’d like to use a sound as a resource in my project in order i only have to spread an exe (without anything else like bitmap/wav).
So i have imported and included into my project a wav file.
Then im trying to use it like that :

m_Musique = FSOUND_Stream_Open(_T(“IDR_WAVE1”), FSOUND_LOOP_NORMAL, 0, 0);

But it seems it doesnt work if i only have my exe, there is no sound playing. Thats why i really would like to know if someone know how to do that, i havent been able to find a sample using resource and not a str *filename.
Thx in advance.

  • You must to post comments
0
0

You need to load the resource into memory, then pass that memory pointer to FSOUND_Stream_Open and tell it to load from memory. All you have done is told FMOD to load a file called IDR_WAVE1 from disk.

  • You must to post comments
0
0

it still doesnt work , my code looks like that now :

[code:1nx1nh1e]
HRSRC rec;
HGLOBAL handle;
void *data;
int length;

FSOUND_Init(44100, 4, 0);
rec = FindResource(NULL, "IDR_WAVE2", RT_RCDATA);
handle = LoadResource(NULL, rec);

data = LockResource(handle);
length = SizeofResource(NULL, rec);

m_Musique = FSOUND_Stream_Open((char *)data, FSOUND_LOADMEMORY, 0, length);

FSOUND_SetVolume(0, 150);
FSOUND_SetVolume(1, 150);
FSOUND_SetVolume(2, 150);
FSOUND_SetVolume(3, 150);

FSOUND_Stream_Play(FSOUND_FREE, m_Musique);
[/code:1nx1nh1e]

i dont know what to do else :/[/code]

  • You must to post comments
0
0

I thought the FindResource/LoadResource methods need the HINSTANCE of the running application. And NULL is only used to get “system” objects.
[code:3421h8hy]HCURSOR cursor = LoadCursor(NULL, IDC_ARROW);
HCURSOR cursor2 = LoadCursor(hInstance, MAKEINTRESOURCE(IDC_MYARROW));
[/code:3421h8hy]

  • You must to post comments
0
0

Incorrect. NULL is used to get a handle to a resource in the image (executable or DLL) that the operating system used to create the process that called FindResource or LoadResource. Basically, from the application that is running.

  • You must to post comments
0
0

Ah… I missed a subtle difference in parameters. HINSTANCE vs. HMODULE. Of course, why not call GetModuleHandle(NULL)? 😉

  • You must to post comments
0
0

Why call GetModuleHandle(NULL) when passing NULL does the same thing?

  • You must to post comments
0
0

No reason. Just being extra careful, or silly. Whichever applies first.

I’m trying to think of cases where the default HMODULE could be wrong. Or if GetModuleHandle(NULL) would refer to a different image than the one implied by just passing a NULL HMODULE.

Needing to load resources from an image that didn’t start the process is one case. But that would need a call like GetModuleHandle(“foo.dll”) or something. And in this case, we know that we are storing the WAVE resource in the .exe.

Ya know… I hate APIs like this. They give you multiple ways to get the same results. I’m sure there are some methods that don’t allow NULL HMODULEs so you need GetModuleHandle(NULL) as a backup. Oh well.

  • You must to post comments
0
0

I created a somewhat ‘blackbox’ routine for getting a ptr (and length) of a resource….

Here’s the code:

[code:2jobh6zj]
void * GetPtrToResource(int resID, const char *resTYPE, DWORD *length)
{
HGLOBAL hGlobal;
HRSRC hRsrc;
CString temp;
void *ptr;

temp.Format("#%d",resID);
hRsrc = FindResource(GetModuleHandle(NULL),(LPCTSTR)temp, resTYPE);
if(hRsrc==NULL) { ptr=NULL; length=0; return ptr; }
hGlobal=(HGLOBAL)LoadResource(GetModuleHandle(NULL),hRsrc);
if(hGlobal==NULL) { ptr=NULL; length=0; return ptr; }
*length = SizeofResource(GetModuleHandle(NULL),hRsrc);
ptr = (void *)LockResource(hGlobal);
return ptr;

}

[/code:2jobh6zj]

Parameters:

[i:2jobh6zj]resID[/i:2jobh6zj] The resource ID, ie, IDB_BITMAP1
[i:2jobh6zj]resTYPE[/i:2jobh6zj] The type of the resource as a string constant, ie, “Bitmap” or “MP3” (the folder name for the resource in VC++)
[i:2jobh6zj]length[/i:2jobh6zj] The length of the resource. (This is an output variable!)

Return value: Returns a void pointer to the resource data. NULL if error occurs.

Example:

Say you have imported a resource “sound.mp3” into your project and the resource folder it is in is “MP3”. It has an identifier of IDR_MP31. To properly call the function do:

[code:2jobh6zj]
.
.
.
void *p;
DWORD len;

p = GetPtrToResource(IDR_MP31, "MP3", &len);
if(p==NULL) { /* do error processing */ }
.
.
.
[/code:2jobh6zj]

This will work with just about ANY resource.

\HP//

  • You must to post comments
Showing 8 results
Your Answer

Please first to submit.