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

## 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);
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
GlobalUnlock(hGlobal);
UnlockResource(hGlob);
FreeResource(hGlob);

bool result = true;
HRESULT hr;
WAVEFORMATEX wf;
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;
}
GlobalFree(hGlobal);
return result;
}


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



bump

##### 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.

• 12
• 10
• 11
• 18
• 13