Správně je to zde:
Imports System.Runtime.InteropServices
Public Class Form1
<DllImport("winmm.dll")> _
Private Shared Function mciSendString(ByVal command As String, ByVal buffer As String, ByVal bufferSize As Integer, ByVal hwndCallback As IntPtr) As Integer
End Function
Private Sub Button_Open_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_Open.Click
mciSendString("set CDAudio door open", vbNullString, 0, IntPtr.Zero)
Me.Text = "opened"
End Sub
Private Sub Button_Close_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_Close.Click
mciSendString("set CDAudio door closed", vbNullString, 0, IntPtr.Zero)
Me.Text = "closed"
End Sub
End Class
Pokud by měl někdo notebook, tak je tu možnost jen otevírat.
Public Class Form1
Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Integer, ByVal dwShareMode As Integer, ByVal lpSecurityAttributes As IntPtr, ByVal dwCreationDisposition As Integer, ByVal dwFlagsAndAttributes As Integer, ByVal hTemplateFile As IntPtr) As IntPtr
Private Declare Function DeviceIoControl Lib "kernel32" (ByVal hDevice As IntPtr, ByVal dwIoControlCode As Integer, ByVal lpInBuffer As IntPtr, ByVal nInBufferSize As Integer, ByVal lpOutBuffer As IntPtr, ByVal nOutBufferSize As Integer, ByRef lpBytesReturned As Integer, ByVal lpOverlapped As IntPtr) As Integer
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As IntPtr) As Integer
Private Const INVALID_HANDLE_VALUE As Integer = -1
Private Const OPEN_EXISTING As Integer = 3
Private Const GENERIC_READ As Integer = &H80000000
Private Const GENERIC_WRITE As Integer = &H40000000
Private Const IOCTL_STORAGE_EJECT_MEDIA As Integer = 2967560
Private Sub EjectCDRom(ByVal driveletter As String)
Dim path As String = "\\.\" + driveletter
If Not path.EndsWith(":") Then path = path + ":"
Dim hDrive As IntPtr = CreateFile(path, GENERIC_READ Or GENERIC_WRITE, 0, IntPtr.Zero, OPEN_EXISTING, 0, IntPtr.Zero)
If CInt(hDrive) = INVALID_HANDLE_VALUE Then Throw New IO.IOException("Could not open drive " + driveletter)
Dim dummy As Integer
DeviceIoControl(hDrive, IOCTL_STORAGE_EJECT_MEDIA, IntPtr.Zero, 0, IntPtr.Zero, 0, dummy, IntPtr.Zero)
CloseHandle(hDrive)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
EjectCDRom("d")
End Sub
End Class
|