Hi
I'm trying to make use of directsound in a .Net project. I haven't much experience with c# so bare over with me.
I have borrowed some code found on the net that I'm trying to merge into my own little project to get a soft start. I'm already failing to initialize the directsound device. Here is what I have:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using Microsoft.DirectX.DirectSound;
using DS = Microsoft.DirectX.DirectSound;
namespace AudioProcessor
{
public class SoundSetup
{
private DS.Device sounddevice;
private SecondaryBuffer shotsound;
public void InitDxSound()
{
sounddevice = new DS.Device();
sounddevice.SetCooperativeLevel(this, CooperativeLevel.Priority);
}
}
static class Program
{
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}
I get the following errors:
Error 1 The best overloaded method match for 'Microsoft.DirectX.DirectSound.Device.SetCooperativeLevel(System.IntPtr, Microsoft.DirectX.DirectSound.CooperativeLevel)' has some invalid arguments
Error 2 Argument '1': cannot convert from 'AudioProcessor.SoundSetup' to 'System.IntPtr'
Can someone please tell me how to resolve this (I suspect that this has to do with the use of "this")?
Best Regards
Thomas
Loading
Sam HobbsPosted Nov 21, 2009, 1:35 PM
So you can change the SoundSetup class to be as: Then when you call InitDxSound, you need to pass a Control. The form is a Control so you can call InitDxSound from the form and pass "this" then.
Sam HobbsPosted Nov 22, 2009, 9:44 AM
Please, if you don't mind, mark my reply as an answer.
ThomasPosted Nov 22, 2009, 5:50 AM
Thanks a lot for your advice - which I will follow.
I can now get sound throughput so I'm very happy :)
Best Regards
Thomas
Sam HobbsPosted Nov 21, 2009, 1:41 PM