_fcloseall () conflicts with DirectMusic 8.1

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: steve (steve_at_mcube.com.tw)
Date: 09/01/04


Date: Wed, 1 Sep 2004 15:45:19 +0800

I made a music.dll for my game.
It works well until I add a C function

_fcloseall ()

before I reload the background music.

The problem results that DirectMusic repeats the wave file at the beginning
portion. However, this unpleasant sound only happens on release version.

Some portion of my music.dll

BOOL
MusicManager::SetBGMusic (LPCTSTR *ppFile, UINT nFile, UINT uVol, UINT
uChangeTime, BOOL bFade)
{
  // free old BGMusic
  Unload (BM_BG_MUSIC);

    hr = CreateSegmentFromFile (&m_pBGMusic[i], ppFile[i], TRUE);

   m_pAudioPath->SetVolume (LogicToPhyVol(uVolume), 0 /*delay mSec*/);

 GetPerformance ()->PlaySegmentEx (m_pSegment, 0, NULL, dwFlags,
   0, 0, NULL, m_pAudioPath);
  }

HRESULT
MusicManager::CreateSegmentFromFile (Music **ppMusic, LPCTSTR szFile, BOOL
bDownloadNow)
{
  HRESULT hr;
  IDirectMusicSegment8 *pSegment = NULL;

  // DMusic only takes wide strings
  WCHAR wszFile[MAX_PATH];
  DXUtil_ConvertGenericStringToWide (wszFile, szFile);

  if (FAILED (hr = m_pLoader->LoadObjectFromFile (CLSID_DirectMusicSegment,
    IID_IDirectMusicSegment8,
    wszFile,
    (LPVOID*) &pSegment)))
  {
    DebugMessage (TEXT("LoadObjectFromFile () Error, file = %s\n"), szFile);
    return hr;
  }

  *ppMusic = new Music (pSegment);
  if (!*ppMusic)
    return E_OUTOFMEMORY;

  if (strstr (szFile, ".mid") || strstr (szFile, ".rmi"))
  {
    if (FAILED (hr = pSegment->SetParam (GUID_StandardMIDIFile, 0xFFFFFFFF,
0, 0, NULL)))
    {
      DebugMessage (TEXT("SetParam () Error\n"));
      return hr;
    }
  }

  if (bDownloadNow)
  {
    if (FAILED (hr = (*ppMusic)->Download ()))
    {
      DebugMessage (TEXT("Download () Error\n"));
      return hr;
    }
  }

  return S_OK;
}



Relevant Pages