Jump to content
  • Advertisement


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


Classes declared as pointers, causing problem

This topic is 5437 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
		m_pDS = NULL;


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

		ZeroMemory( &dsbd, sizeof(DSBUFFERDESC) );
		dsbd.dwSize        = sizeof(DSBUFFERDESC);
		dsbd.dwFlags       = DSBCAPS_PRIMARYBUFFER;
		dsbd.dwBufferBytes = 0;
		dsbd.lpwfxFormat   = NULL;
		m_pDS->CreateSoundBuffer( &dsbd, &pDSBPrimary, NULL ) ;
		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);

thanks [edited by - johnnyBravo on November 26, 2003 11:12:38 PM]

Share this post

Link to post
Share on other sites
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.

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!