|
-
November 27th, 2009, 08:11 PM
#1
Eject dvd rom in C#
Hi. I'm pretty new to C# and programming at all. And i wonder how you exactly can eject/open your dvd reader when you press a button. And please be nice and tell me all code, I mean if there are any system. code and such.
Happy and great full for serious answers Hi. I'm pretty new to C# and programming at all. And i wonder how you exactly can eject/open your dvd reader when you press a button. And please be nice and tell me all code, I mean if there are any system. code and such.
Happy and great full for serious answers
-
November 28th, 2009, 09:31 AM
#2
Re: Eject dvd rom in C#
You'll have to use interop. Here is a link to everything you'll need.
First, you'll have to call CreateFile to get a handle to the drive. Next, you'll have to call DeviceIOControl to eject the drive. And finally, you'll have to call CloseHandle to close the drive handle.
Assuming that your eject class is named DVD and that your DVD is the E: drive, you would initiate the ejection process as follows:
Code:
DVD.Eject(@"\\.\E:");
Also, you'll need the following constants:
Code:
const uint GENERICREAD = 0x80000000;
const uint OPENEXISTING = 3;
const uint IOCTL_STORAGE_EJECT_MEDIA = 2967560;
const int INVALID_HANDLE = -1;
This is also needed:
Code:
using System.Runtime.InteropServices;
-
November 28th, 2009, 02:29 PM
#3
Re: Eject dvd rom in C#
Use the mciSendString. Here's a link: http://www.devx.com/tips/Tip/13324
Code:
Public Class Form1
Declare Function mciSendString Lib "winmm" Alias "mciSendStringA" (ByVal _
lpstrCommand As String, ByVal lpstrReturnString As String, _
ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
mciSendString("Set CDAudio Door Open Wait", 0&, 0&, 0&)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
mciSendString("Set CDAudio Door Closed Wait", 0&, 0&, 0&)
End Sub
End Class
-
November 29th, 2009, 07:22 PM
#4
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|