1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
public class OpenOrCloseCDDrive
{
[DllImport("winmm.dll", CharSet = CharSet.Auto, EntryPoint = "mciSendString")]
public static extern int MciSendString(string command,
StringBuilder buffer, int bufferSize, IntPtr hwndCallback);
protected const int IntMciSuccess = 0;
protected const int IntBufferSize = 127;
protected List<DriveInfo> listCDDrives = new List<DriveInfo>();
public List<DriveInfo> GetCDDrives
{
get
{
return listCDDrives;
}
}
public OpenOrCloseCDDrive()
{
DriveInfo[] drives = DriveInfo.GetDrives();
foreach (DriveInfo drive in drives)
{
if (drive.DriveType == DriveType.CDRom)
{
listCDDrives.Add(drive);
}
}
}
public void Open(DriveInfo cdDrive)
{
if (cdDrive.DriveType != DriveType.CDRom)
{
throw new InvalidOperationException
("Der übergebene Parameter enthält kein gültiges CD/DVD-Laufwerk");
}
StringBuilder buffer = new StringBuilder();
int errorCode = MciSendString
(
(
String.Format
("set CDAudio!{0} door open", cdDrive.Name)
),
buffer,
IntBufferSize,
IntPtr.Zero
);
}
public void Close(DriveInfo cdDrive)
{
if (cdDrive.DriveType != DriveType.CDRom)
{
throw new InvalidOperationException
("Der übergebene Parameter enthält kein gültiges CD/DVD-Laufwerk");
}
StringBuilder buffer = new StringBuilder();
int errorCode = MciSendString
(
(
String.Format
("set CDAudio!{0} door closed", cdDrive.Name)
),
buffer,
IntBufferSize,
IntPtr.Zero
);
}
}
|