1) Typically, you'd use the handle for the main form in the call to SetCooperativeLevel.
2) Can you post all the relevant code?
My attempted program consists of the files Form0.cs, Form0.designer.cs, Program.cs, and Form1.cs. The first three were produced by Visual Studio by my starting what they call a "windows application". The last is my own attempt to adapt the code from "DirectX SDK\DirectX Documentation\DirectX Documentation for Managed Languages\Direct Sound\Playing Sounds".
// Form0.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.DirectX.DirectSound;
namespace TryPlay0
{
public partial class Form0 : Form
{
public Form0()
{
InitializeComponent();
}
private void Form0_Load(object sender, EventArgs e)
{
Device dsDevice = null;
dsDevice = new Device();
return;
}
}
public class wfEnum : Form
{
private DevicesCollection myDevices = null;
private struct myDeviceDescription
{
public DeviceInformation info;
public override string ToString()
{
return info.Description;
}
public myDeviceDescription(DeviceInformation di)
{
info = di;
}
}
public wfEnum()
{
// Retrieve the available DirectSound devices
myDevices = new DevicesCollection();
foreach (DeviceInformation dev in myDevices)
{
myDeviceDescription dd = new myDeviceDescription(dev);
// Use DevicesCollection and DeviceInformation to query for devices.
}
}
public static Device dsDevice = null;
}
}
///Form0.Designer.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.DirectX.DirectSound;
namespace TryPlay0
{
partial class Form0
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(121, 112);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 0;
this.button1.Text = "button1";
this.button1.UseVisualStyleBackColor = true;
//
// Form0
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(292, 273);
this.Controls.Add(this.button1);
this.Name = "Form0";
this.Text = "Form0";
this.Load += new System.EventHandler(this.Form0_Load);
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.Button button1;
}
}
//Program.cs
using System;
using System.Collections.Generic;
using System.Windows.Forms;
namespace TryPlay0
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form0());
}
}
}
//Form1.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.DirectX.DirectSound;
//[C#]
using Microsoft.DirectX.DirectSound;
public class wfEnum : Form
{
private DevicesCollection myDevices = null;
private struct myDeviceDescription
{
public DeviceInformation info;
public override string ToString()
{
return info.Description;
}
public myDeviceDescription(DeviceInformation di)
{
info = di;
}
}
public wfEnum()
{
// Retrieve the available DirectSound devices
myDevices = new DevicesCollection();
foreach (DeviceInformation dev in myDevices)
{
myDeviceDescription dd = new myDeviceDescription(dev);
// Use DevicesCollection and DeviceInformation to query for devices.
}
}
private Device dsDevice/* = null*/;
}
//Thank you for your help.