Jump to content
  • Advertisement

Archived

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

Classes declared as pointers, causing problem

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

In the directsound playsound example in directx 9 sdk, they have a class called CSoundManager that is called like this: CSoundManager * g_pSoundManager; g_pSoundManager = new CSoundManager(); g_pSoundManager->Initialize( hWnd ) ; Ive been messing around with the sample code and making it much smaller. The problem is i dont want to declare the CSoundManager as a pointer. But as such: CSoundManager g_pSoundManager; g_pSoundManager.Initialize( hWnd ) ; But when I do this directsound will not initialise. Heres my class code:
class CSoundManager
{
public:
	static LPDIRECTSOUND8 m_pDS;
	CSoundManager()
	{
		m_pDS = NULL;
	}

	~CSoundManager()
	{
		if(m_pDS)
		{ 
			(m_pDS)->Release(); 
			(m_pDS)=NULL;
		}
	}

	void Initialize( HWND  hWnd   )
	{
		DirectSoundCreate8( NULL, &m_pDS, NULL );
		m_pDS->SetCooperativeLevel( hWnd, DSSCL_PRIORITY );
		LPDIRECTSOUNDBUFFER pDSBPrimary = NULL;

		DSBUFFERDESC dsbd;
		ZeroMemory( &dsbd, sizeof(DSBUFFERDESC) );
		dsbd.dwSize        = sizeof(DSBUFFERDESC);
		dsbd.dwFlags       = DSBCAPS_PRIMARYBUFFER;
		dsbd.dwBufferBytes = 0;
		dsbd.lpwfxFormat   = NULL;
		m_pDS->CreateSoundBuffer( &dsbd, &pDSBPrimary, NULL ) ;
		
		WAVEFORMATEX wfx;
		ZeroMemory( &wfx, sizeof(WAVEFORMATEX) ); 
		wfx.wFormatTag      = (WORD) WAVE_FORMAT_PCM; 
		wfx.nChannels       =  2; 
		wfx.nSamplesPerSec  = 22050; 
		wfx.wBitsPerSample  = (WORD) 16; 
		wfx.nBlockAlign     = (WORD) (wfx.wBitsPerSample / 8 * wfx.nChannels);
		wfx.nAvgBytesPerSec = (DWORD) (wfx.nSamplesPerSec * wfx.nBlockAlign);

		pDSBPrimary->SetFormat(&wfx);
		
		if(pDSBPrimary)
		{ 
			(pDSBPrimary)->Release(); 
			(pDSBPrimary)=NULL;
		}	
	}
};
LPDIRECTSOUND8 CSoundManager::m_pDS=NULL;
thanks [edited by - johnnyBravo on November 26, 2003 11:12:38 PM]

Share this post


Link to post
Share on other sites
Advertisement
Three things:

1) It shouldn''t make a difference.
2) What do you mean by ''directsound will not initialise''?
2) Why don''t you want to use pointers?

Share this post


Link to post
Share on other sites
well if i change the class declaration from not using pointers , the speakers click and nothing plays, as ive got another class that loads and plays sounds

i don''t want to use pointers as i have a wrapper that i want the declaration of every class consistent. As i dont use pointers in the declartion of any of my classes.

Share this post


Link to post
Share on other sites
It is probably a scope problem. I''m guessing your class that you instantiate goes out of scope and thus deletes the interfaces that are actually playing the sounds. (Note: Never actually done anything in DirectSound).
Try creating the instance globally (a global variable of CSoundManager) and then playing it, does anything happen?

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!