Sign in to follow this  

Problem with DirectMusic

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

This topic is 4110 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this