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.
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.