C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




How to open the CD TRAY using c# code


Posted Date: 14 Jun 2008    Resource Type: Code Snippets    Category: Console Applications
Author: Arnab BhuyanMember Level: Bronze    
Rating: Points: 10



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

}
}
}




Responses

Author: Kapil Dhawan    18 Jun 2008Member 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 2008Member Level: Diamond   Points : 0
Thanks for sharing


Author: RamyaNaidu    06 Aug 2008Member 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);
}
}





Feedbacks      
Popular Tags   What are tags ?   Search Tags  
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: LinkList using C#
Previous Resource: Delegates - A simple way
Return to Discussion Resource Index
Post New Resource
Category: Console Applications


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design


Contact Us    Privacy Policy    Terms Of Use