I am writing a small toy on WPF, and I use DirectSound to play many sounds simultaneously. Before that I tried to use AudioVideoPlayback, but there was exactly the same problem. I added a DirectSound.dll link to the project from the DirectX folder.

Registered

using Microsoft.DirectX.DirectSound; 

These lines are responsible for initialization:

  Microsoft.DirectX.DirectSound.Buffer sp; Microsoft.DirectX.DirectSound.Buffer deathSp; Device m_SoundDevice; 

In the window constructor, I allocate memory, load everything:

  m_SoundDevice = new Device(); m_SoundDevice.SetCooperativeLevel((new system.Windows.Interop.WindowInteropHelper(this)).Handle, CooperativeLevel.Priority); sp = new Microsoft.DirectX.DirectSound.Buffer("Shot2.wav", m_SoundDevice); deathSp = new Microsoft.DirectX.DirectSound.Buffer("Death1.wav", m_SoundDevice); 

The problem is that if the project properties have .NET 4.0 or higher, then when debugging, the studio sometimes just freezes, and closes only by completing the studio process, sometimes it immediately gives an error, as in versions 3.X. The compiled version of the file gives an error at startup. If you lower the version of .NET to 3.5 or 3.0, then when debugging, the program starts, but crashes during initialization, which I indicated above. Writes the following:

No source files available. The call stack contains only external code.

XamlParseException is not processed. A call to the constructor for the type Game.MainWindow that satisfies the specified binding constraints resulted in an exception. ": Line number" 3 "and position in line" 9 ".

I do not understand the reason. Where is this third line - too. In xaml in the 3rd line there is nothing interesting, as in the code on the 3rd line.

  • These Russian error messages are only misleading. On which line is an exception thrown? Show the full call stack. - nitrocaster

1 answer 1

Uff, I figured out the problem. The reason was that it was impossible to set the CooperativeLevel for SoundDevice during the initialization of our MainWindow . The initialization of the entire DirectSound should be hung on the OnLoad event OnLoad our main window, or at any time after its initialization is completed.