Hey all,
Not really sure if this is the appropriate place for DirectSound-related questions but the other MSDN forums forwarded me here.
I'm trying to create a class library that serves as a wrapper for some sound-related functionality. I've chosen DirectSound as it seems to have the richest feature set for the job! The problem is that, when instantiating a new device, you are required to call SetCooperativeLevel() for..whatever reason...and, as a parameter, you're required to pass either an IntPtr to a window handle of a reference to an object of type Control.
The problem is that, since I'm in a class library context, I don't have an available window handle or object of type Control! I've tried creating an object locally and passing that to no avail. I'm wondering if anyone has a hack for this or has tried (and succeeded) in getting this to work somehow?
Any insight you guys can provide would be really great!
Thanks
Relevant Code:
| private Form _parent; |
| |
| public SoundGenerator() |
| { |
| this._parent = new Form(); // We don't really need this... |
| this._parent.CreateControl(); |
| |
| this._InitializeSoundDevices(); |
| } |
| |
| private void _InitializeSoundDevices() |
| { |
| Debug.WriteLine(">> SoundGenerator._InitializeSoundDevices"); |
| |
| this._device = new Device(DSoundHelper.DefaultPlaybackDevice); |
| |
| this._device.SetCooperativeLevel(this._parent, CooperativeLevel.Priority); |
| this._soundDescription = new BufferDescription(); |
| |
| this._soundDescription.ControlPan = false; |
| this._soundDescription.ControlVolume = true; |
| this._soundDescription.ControlFrequency = false; |
| this._soundDescription.ControlEffects = false; |
| Debug.WriteLine("<< SoundGenerator._InitializeSoundDevices"); |
| } |