This is another approach using a dll, full simple app provided
Hope this helps
Publicjoe
C# Tutorial at
http://www.publicjoe.f9.co.uk/csharp/tut.html
C# Ebook at
http://www.publicjoe.f9.co.uk/csharp/samples/ebook.html - 72
Chapters
VB Ebook at
http://www.publicjoe.f9.co.uk/vbnet/samples/ebook.html - 28
Chapters
C++ Ebook at
http://www.publicjoe.f9.co.uk/cppt/samples/ebook.html - 8
Chapters
Java Ebook at
http://www.publicjoe.f9.co.uk/java/samples/ebook.html - 2
Chapters
Mirrors at
http://dowhileloop.com/publicjoe/ and
http://publicjoe.justbe.com/
///--- Beginning of code ---///
using System;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
public class CDFrm : Form
{
private System.ComponentModel.Container components = null;
private Button btn1;
private Button btn2;
// Constructor
public CDFrm()
{
InitializeComponent();
}
// Clean up any resources being used.
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
// Initialize form components
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.Text = "CD Demo";
this.Size = new Size( 200, 100 );
// Button initialization and setup
btn1 = new Button();
btn1.Text = "Open";
btn1.Location = new Point( 20, 15 );
btn1.Size = new Size( 70, 20 );
btn2 = new Button();
btn2.Text = "Close";
btn2.Location = new Point( 110, 15 );
btn2.Size = new Size( 70, 20 );
// Add the Buttons to the Form
this.Controls.Add( btn1 );
this.Controls.Add( btn2 );
// Add Event for Button Click
btn1.Click += new EventHandler(btnEject_Click);
btn2.Click += new EventHandler(btnClose_Click);
}
// The main entry point for the application.
[STAThread]
static void Main()
{
Application.Run( new CDFrm() );
}
// Event for Open Button Click
private void btnEject_Click( object sender, System.EventArgs e )
{
int ret = mciSendString( "set cdaudio door open", null, 0,
IntPtr.Zero );
}
// Event for Close Button Click
private void btnClose_Click( object sender, System.EventArgs e )
{
int ret = mciSendString( "set cdaudio door closed", null, 0,
IntPtr.Zero );
}
// DLL access
[DllImport( "winmm.dll", EntryPoint="mciSendStringA",
CharSet=CharSet.Ansi )]
protected static extern int mciSendString( string lpstrCommand,
StringBuilder
lpstrReturnString,
int uReturnLength,
IntPtr hwndCallback );
}
///--- End of code ---///