The following code snippet shows how to open the CD TRAY using c# code
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Runtime.InteropServices;
namespace play { class Program { [DllImport("winmm.dll")] public static extern void mciSendString(string s1,string s2, int i,int j);
static void Main(string[] args) { char ch; Console.Write("Enter 'O' to open CD Tray! : "); ch = Console.ReadKey().KeyChar;
if (ch =='O' || ch == 'o') { mciSendString("set cdaudio door open",null,0,0); } Console.WriteLine(); Console.Write("Enter 'C' to close CD Tray! : "); ch=Console.ReadKey().KeyChar; if (ch == 'C' || ch == 'c') { mciSendString("set cdaudio door closed", null, 0, 0); }
} } }
|
| Author: Kapil Dhawan 18 Jun 2008 | Member Level: Gold Points : 2 |
Hello Nice piece of code Thanks for sharing your knowledge with us. I hope to see more good code from your side This code will help lots of guys Thanks to you Regards, Kapil
|
| Author: Shivshanker Cheral 18 Jun 2008 | Member Level: Diamond Points : 0 |
Thanks for sharing
|
| Author: RamyaNaidu 06 Aug 2008 | Member Level: Silver Points : 2 |
using System; using System.Collections.Generic; using System.Text; using System.Runtime.InteropServices;
namespace ConsoleApplication2 { class Program { static void Main(string[] args) { int Res = mciSendString ("set cdaudio door open", null, 0, IntPtr.Zero); Res = mciSendString("set cdaudio door closed", null, 0, IntPtr.Zero);
} [DllImport("winmm.dll", EntryPoint = "mciSendStringA", CharSet = CharSet.Ansi)] protected static extern int mciSendString (string mciCommand, StringBuilder returnValue, int returnLength, IntPtr callback); } }
|