Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Loading and playing an Object from a Resource or Memory Address

This topic is 5297 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

Can somebody tell me how to play a sound from a Resource DLL? I use the following functions: // sets up a sound HRESULT C3DSound::Setup(HMODULE hMod, WORD wResourceID, IDirectMusicPerformance8* pPerformance, IDirectMusicLoader8* pLoader){ HRESULT hr; DMUS_OBJECTDESC objDesc; m_pLoader = pLoader; HRSRC hFound = FindResource(hMod, MAKEINTRESOURCE(wResourceID), "WAVE"); HGLOBAL hRes = LoadResource(hMod, hFound); if (NULL == hRes) return E_FAIL; objDesc.dwSize = sizeof(DMUS_OBJECTDESC); objDesc.guidClass = CLSID_DirectMusicSegment; objDesc.dwValidData = DMUS_OBJ_CLASS | DMUS_OBJ_MEMORY; objDesc.pbMemData = (BYTE *) LockResource(hRes); objDesc.llMemLength = SizeofResource(hMod, hFound); if (m_pLoader){ hr = m_pLoader->GetObject( &objDesc, IID_IDirectMusicSegment8, (LPVOID*) &m_pSegment); } else{ return E_INVALIDARG; } // Download the segment''s instruments to the synthesizer if (FAILED(hr = m_pSegment->Download( m_pPerformance ))) return hr; // by default don''t repeat soundss if (FAILED(hr = m_pSegment->SetRepeats( 0 ))) return hr; // Create the 3D audiopath with a 3d buffer. // We can then play this segment through this audiopath (and hence the buffer) // and alter its 3D parameters. if (FAILED(hr = m_pPerformance->CreateStandardAudioPath( DMUS_APATH_DYNAMIC_3D, 64, TRUE, &m_p3DAudioPath ))) return hr; // Get the IDirectSound3DBuffer8 from the 3D audiopath if (FAILED(hr = m_p3DAudioPath->GetObjectInPath( DMUS_PCHANNEL_ALL, DMUS_PATH_BUFFER, 0, GUID_NULL, 0, IID_IDirectSound3DBuffer, (LPVOID*) &m_pDSB ))) return hr; // get the listener from the 3d audiopath if (FAILED(m_p3DAudioPath->GetObjectInPath(0, DMUS_PATH_PRIMARY_BUFFER, 0, GUID_All_Objects, 0, IID_IDirectSound3DListener, (void **)&m_pListener))) return hr; return S_OK; } When I execute this function it returns S_OK so everything goes well (I Guess) but when I try to play the sound I loaded with the following code: // play the sound HRESULT C3DSound:lay(bool bLoop){ HRESULT hr; if (bLoop) // Tell DirectMusic to repeat this segment forever if (FAILED(hr = m_pSegment->SetRepeats( DMUS_SEG_REPEAT_INFINITE ))) return hr; // Play segment on the 3D audiopath if (FAILED(hr = m_pPerformance->PlaySegmentEx( m_pSegment, NULL, NULL, DMUS_SEGF_SECONDARY, 0, NULL, NULL, m_p3DAudioPath ))) return hr; return S_OK; } I get a first chance exception. Does anybody know what I''m doing wrong?

Share this post

Link to post
Share on other sites

  • 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!