XNA Creators Club Online
Page 1 of 1 (4 items)
Sort Posts: Previous Next

DirectSound: Device.SetCooperativeLevel() and handles in class libraries

Last post 5/27/2009 8:06 PM by Abhishek Ramkumar. 3 replies.
  • 5/12/2009 9:25 AM

    DirectSound: Device.SetCooperativeLevel() and handles in class libraries

    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"); 

  • 5/15/2009 7:26 AM In reply to

    Re: DirectSound: Device.SetCooperativeLevel() and handles in class libraries

    Hi,

    you need to specify the cooerative level to determine how DirectSound should behave if more than one instance of DirectSound is running at the same time. 
    This behavior is related to the focus, and the focus is 'linked' to a visible item. 
    You might try to use just zero as the handle.

    Tomy
  • 5/25/2009 2:44 AM In reply to

    Re: DirectSound: Device.SetCooperativeLevel() and handles in class libraries

    Hello Brad,

    Any luck with this issue?

    I'm really struggling as well with this as it seems that all sample code I find is using a window/form as support.

    I would like to write a simple standalone (or a DLL) that doesn't open a window. It just plays a sound and quits.
    If I pass null as the owner to Device.SetCooperativeLevel then I get an error.

    Any help would be very very much appreciated as I've been Googling my head off on this.
  • 5/27/2009 8:06 PM In reply to

    Re: DirectSound: Device.SetCooperativeLevel() and handles in class libraries

    Hey Brad and ultragotcha,

    Any luck resolving the issue?

    I am facing a similar problem - I am writing a dll in VC++ with an exported function that will initialize a joystick and apply force-feedback using DirectInput. Since SetCooperativeLevel needs a handle to a window (HWND) so that it can be accessed, I am having trouble initializing it. I plan to access the function via LabView so that it can control the force-feedback.

    Any help or direction with regards to this will be very much appreciated. I have been breaking my head over this for over 2 weeks now.

    Thanks in advance!
    Cheers,
    Abhishek
Page 1 of 1 (4 items) Previous Next