Jump to content
  • Advertisement
Sign in to follow this  

Loading .wav from resource (crashes)

This topic is 4371 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm a bit of a novice when it comes to loading things from resources, and still more a novice when it comes to Direct sound. Therefore I'm using the CSoundManager and CSound classes, but I am still having trouble. The following is my code to load my sound from memory, but it does not work (program crashes when it tries to load). Could someone give me a few tips? Thanks -Mike

CSoundManager* g_pSoundManager = NULL;
CSound*        g_pSound[gCGNumSounds];

bool loadSoundFromRes(int s_i, char *pResourceName, char *pResourceType) {
	// from resources
	HRSRC hRes;
	hRes = FindResource(NULL, pResourceName, pResourceType);

	DWORD	dwDataSize	= SizeofResource(NULL,hRes);
	HGLOBAL	hGlob		= LoadResource(NULL,hRes);
	LPVOID	pData		= LockResource(hGlob);

	// allocate some global memory and copy the resource data into it..
	HGLOBAL hGlobal = GlobalAlloc(GMEM_MOVEABLE, dwDataSize);
	void* pData2 = GlobalLock(hGlobal);
	memcpy(pData2, pData, dwDataSize);

	// unlock and free the resource

	bool result = true;
	if (FAILED(hr = g_pSoundManager->CreateFromMemory(&g_pSound[s_i], (BYTE*)pData2, dwDataSize, &wf))) 
		MessageBox( hWnd, "Could not load .wav file from resources!", "Error", MB_OK | MB_ICONERROR );
		result = false;
	return result;

I'm calling this function with:
if (loadSoundFromRes(s_i, MAKEINTRESOURCE(IDR_ARCSWAP), "WAV") == false) failed = true;

Share this post

Link to post
Share on other sites
Well, you've told us virtually nothing about the nature of the crash, i.e. where it crashes in that function, values you are passing that function, or indeed if the objects involved are valid. I would start with running the program with your debugger and see exactly where it crashes. Then you can work from that point backwards through the callstack as necessary.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!