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 HobbsRank #107 · 20.5K reputationPosted Nov 21, 2009, 8:35 AM EST
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 HobbsRank #107 · 20.5K reputationPosted Nov 21, 2009, 8:41 AM EST
Thomas7 reputationPosted Nov 22, 2009, 12:50 AM EST
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 HobbsRank #107 · 20.5K reputationPosted Nov 22, 2009, 4:44 AM EST
Please, if you don't mind, mark my reply as an answer.