Jump to content
  • Advertisement
Sign in to follow this  
K A Z E

Problem with DirectMusic

This topic is 4412 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 trying to setup DirectMusic and get it to play a wav. And it works. Problem is when I try to switch the window to fullscreen/windowed it crashes. I'm using a modified version of NeHe's OpenGL template. And to switch to fullscreen/windowed I destroy the window and re-create it (either with WS_POPUP for fullscreen or WS_OVERLAPPEDWINDOW for windowed, and call ChangeDisplaySettings for fullscreen mode). It does NOT crash, however, if I exit and just destroy the window. So re-creating it must be doing it... I call CoUninitialize when I destroy the window, and I release all my objects, so I don't know what's wrong. Sometimes I get that blah blah has encountered an error and needs to close error box and sometimes I get "The instruction at 0x6c994984 referenced memory at 0x6c994984. The memory could not be read." I have ran through in debug mode and try to see if any of my interface pointers had that address, but none that I saw did. Here's my code for setting up DirectMusic:
// My globals
IDirectMusicPerformance8* DMPerformance = NULL;
IDirectMusicLoader8*      DMLoader      = NULL;
IDirectMusicSegment8*     DMSegment     = NULL;

// The code from my CleanUp function that's called when I destroy the window
if(DMPerformance)
{
	DMPerformance->Stop(NULL, NULL, 0, NULL);
	DMPerformance->CloseDown();
	DMPerformance->Release();
	DMPerformance = NULL;
}
if(DMLoader)
{
	DMLoader->Release();
	DMLoader = NULL;
}
if(DMSegment)
{
	DMSegment->Release();
	DMSegment = NULL;
}
CoUninitialize();

// Sets up DirectMusic
bool InitializeDMusic()
{
	CoInitialize(NULL);
	if(FAILED(CoCreateInstance(CLSID_DirectMusicPerformance, NULL, CLSCTX_INPROC, IID_IDirectMusicPerformance8, (void**)&DMPerformance)))
	{
		MessageBox(NULL, "Couldn't initialize DirectMusic. Creation of the performance object failed.", "Error", MB_OK | MB_ICONSTOP);
		return FALSE;
	}
	if(FAILED(DMPerformance->InitAudio(NULL, NULL, hWnd, DMUS_APATH_SHARED_STEREOPLUSREVERB, 64, DMUS_AUDIOF_ALL, NULL)))
	{
		MessageBox(NULL, "Couldn't initialize DirectMusic. DMPerformance->InitAudio failed.", "Error", MB_OK | MB_ICONSTOP);
		return FALSE;
	}
	if(FAILED(CoCreateInstance(CLSID_DirectMusicLoader, NULL, CLSCTX_INPROC, IID_IDirectMusicLoader8, (void**)&DMLoader)))
	{
		MessageBox(NULL, "Couldn't initialize DirectMusic. Creation of the loader object failed.", "Error", MB_OK | MB_ICONSTOP);
		return FALSE;
	}
	if(FAILED(CoCreateInstance(CLSID_DirectMusicSegment, NULL, CLSCTX_INPROC, IID_IDirectMusicSegment8, (void**)&DMSegment)))
	{
		MessageBox(NULL, "Couldn't initialize DirectMusic. Creation of the segment object failed.", "Error", MB_OK | MB_ICONSTOP);
		return FALSE;
	}
	DMLoader->SetSearchDirectory(GUID_DirectMusicAllTypes, L"C:/Documents and Settings/Owner/Desktop/", FALSE);
	if(FAILED(DMLoader->LoadObjectFromFile(CLSID_DirectMusicSegment, IID_IDirectMusicSegment8, L"Music.wav", (void**)&DMSegment)))
	{
		MessageBox(NULL, "Couldn't initialize DirectMusic. Attempt to load the music file failed.", "Error", MB_OK | MB_ICONSTOP);
		return FALSE;
	}
	if(FAILED(DMSegment->Download(DMPerformance)))
	{
		MessageBox(NULL, "Couldn't initialize DirectMusic. DMSegment->Download failed.", "Error", MB_OK | MB_ICONSTOP);
		return FALSE;
	}
	DMSegment->SetRepeats(DMUS_SEG_REPEAT_INFINITE);
	DMPerformance->PlaySegmentEx(DMSegment, NULL, NULL, NULL, 0, NULL, NULL, NULL);
	return TRUE;
}

As a side question, is there a way to change the window style of a window without having to recreate it? Help would be appreciated. Thanks in advance.

Share this post


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