#### Archived

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

# IDirectMusic8 crash my program!!! why?

This topic is 5453 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

here is the code (it''s from 2kings a bit modified) when I run the program at the first time, all is good, I can hear the sound file but when I quit the program and run it again, the computer crash, and I need to restart computer... here is the code, a bit long, but please help me!
class CSound
{
public:
void Play();
void Stop();
bool IsPlaying();
void ShutDownSound();
private:
IDirectMusicPerformance8*		Performance;
IDirectMusicSegment8*		Segment;
};

void CSound::Load(CAudio Audio,char *file)
{
WCHAR wcFile[MAX_PATH];
Segment=NULL;
Performance=Audio.GetPerformance();
CoCreateInstance(CLSID_DirectMusicSegment,NULL,CLSCTX_INPROC,IID_IDirectMusicSegment8,(void**)&Segment);
MultiByteToWideChar(CP_ACP,0,file,-1,wcFile,MAX_PATH);
}
void CSound::Play()
{
Performance->PlaySegmentEx(Segment,0,NULL,DMUS_SEGF_SECONDARY,0,0,NULL,NULL);
}
void CSound::Stop()
{
Performance->StopEx(Segment,0,0);
}
bool CSound::IsPlaying()
{
return (Performance->IsPlaying(Segment,NULL) == S_OK);
}

void CSound::ShutDownSound()
{
Segment->Release();
CoUninitialize();
}

class CAudio
{
public:
void InitAudio();
void SetFilesDirectory();
void ShutDownAutdio();
void SetMasterVolume(long volume);
inline IDirectMusicPerformance8* GetPerformance()
{
return Performance;
}
{
}
private:
IDirectMusicPerformance8 *Performance;
};

void CAudio::InitAudio()
{
CoInitialize(NULL);
CoCreateInstance(CLSID_DirectMusicPerformance,NULL,CLSCTX_INPROC,IID_IDirectMusicPerformance8,(void**)&Performance);
Performance->InitAudio(NULL,NULL,NULL,DMUS_APATH_DYNAMIC_STEREO,64,DMUS_AUDIOF_ALL,NULL);
SetFilesDirectory();
}
void CAudio::SetFilesDirectory()
{
char szSearchPath[MAX_PATH];

GetCurrentDirectory(MAX_PATH,szSearchPath);
strcat(szSearchPath,"//sounds");

WCHAR wszSearchPath[MAX_PATH];
MultiByteToWideChar(CP_ACP,0,szSearchPath,-1,wszSearchPath,MAX_PATH);

}

void CAudio::ShutDownAutdio()
{
Performance->Stop(NULL,NULL,0,0);
Performance->CloseDown();
Performance->Release();
CoUninitialize();
}

void CAudio::SetMasterVolume(long volume)
{
Performance->SetGlobalParam(GUID_PerfMasterVolume,&volume,sizeof(long));
}


##### Share on other sites

I tried to figure what is the problem but I dont know why this happens...

I think the problem is that I''m not releasing them good, but I call the ShutDownSound() and ShutAudio()

##### Share on other sites
im totally new to programing so i dont know anything yet, but when i ws looking through the code box thigies, I went to the last one and saw this bit

strcat(szSearchPath,"//sounds");

//means comment and so the closing of the " is not closed, its part of the comment, and so the rest of the code from then on is just part of a string.

Probably got nothing todo with that, but i saw that as i was scrolling past :/

##### Share on other sites
Get rid of the CoUninitialize call in the CSound class as it never calls CoInitialize(Ex). That''s one error I can spot that might possibly lead to that kind of behavior.

##### Share on other sites
Mastaba:thanks, I did but the problem is not in CSound, it''s in CAudio...

##### Share on other sites
quote:
Original post by Pred
im totally new to programing so i dont know anything yet, but when i ws looking through the code box thigies, I went to the last one and saw this bit

strcat(szSearchPath,"//sounds");

//means comment and so the closing of the " is not closed, its part of the comment, and so the rest of the code from then on is just part of a string.

Probably got nothing todo with that, but i saw that as i was scrolling past :/

I think the quotes have higher priority than the slashes (comments).

--
You''re Welcome,
Rick Wong
- sitting in his chair doing the most time-consuming thing..

##### Share on other sites
quote:
Original post by Ilankt
Mastaba:thanks, I did but the problem is not in CSound, it''s in CAudio...

But, having CoUninitialize in CSound was a problem none the less. One that would screw up the CAudio shutdown since the directmusic dll''s would get unloaded prematurely.

1. 1
2. 2
3. 3
Rutin
22
4. 4
5. 5

• 11
• 17
• 14
• 9
• 9
• ### Forum Statistics

• Total Topics
632929
• Total Posts
3009278
• ### Who's Online (See full list)

There are no registered users currently online

×