|
-
January 22nd, 2010, 10:41 PM
#1
What am i doing wrong?
ok i wanted to make a button to open/close the CD tray i have the code to do it but when i compile it nothing happens could somebody please tell me what i did wrong.
Code:
Public Class Form1
Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long
Function CDDriveOperation(ByVal Command As String, ByVal hWnd As Long) As String
Dim Buff As String
Dim dwR As Long
Buff = Space$(100) ' Create a buffer
dwR = mciSendString(Command, ByVal Buff, Len(Buff), hWnd)
CDDriveOperation = Buff
End Function
'Call this Sub to Close the CD Door
Private Sub CloseCDDoor()
Dim ret As String
ret = CDDriveOperation("set cdaudio door closed", 0)
End Sub
' Call this Sub to Open the CD Door
Private Sub OpenCDDoor()
Dim ret As String
ret = CDDriveOperation("set cdaudio door open", 0)
End Sub
End Class
-
January 22nd, 2010, 10:43 PM
#2
Re: What am i doing wrong?
Probably declared it wrong...
Code:
Option Explicit
' add Microsoft Multimedia Control component
Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" _
(ByVal lpCommandString As String, ByVal lpReturnString As String, _
ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long
Private Sub Form_Load()
OpenCDDoor
CloseCDDoor
End Sub
Public Sub OpenCDDoor()
Dim retval As Long
retval = mciSendString("set CDAudio door open", "", 0, 0)
End Sub
Public Sub CloseCDDoor()
Dim retval As Long
retval = mciSendString("set CDAudio door closed", "", 0, 0)
End Sub
EDIT: Command is a reserved word, I think. I don't know what you are passing as command, either
-
January 25th, 2010, 11:31 AM
#3
Re: What am i doing wrong?
OK, firstly, my default CD ROM / DVD ROM drive is not D:\, it is F:\.
I always have to do this :
Code:
Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long
Dim sDriveLetter As String
Dim sAlias As String
Private Sub Command3_Click()
sDriveLetter = "F"
sAlias = "CD" & sDriveLetter
mciSendString "open " & sDriveLetter & ": type cdaudio alias " & sAlias & " wait", returnstring, 0&, 0&
mciSendString "set " & sAlias & " door open wait", returnstring, 0&, 0&
mciSendString "close " & sAlias, returnstring, 0&, 0&
End Sub
Private Sub Command4_Click()
sDriveLetter = "F"
sAlias = "CD" & sDriveLetter
mciSendString "open " & sDriveLetter & ": type cdaudio alias " & sAlias & " wait", returnstring, 0&, 0&
mciSendString "set " & sAlias & " door closed wait", returnstring, 0&, 0&
mciSendString "close " & sAlias, returnstring, 0&, 0&
End Sub
My advice is, substitute sDriveLetter = "F" with sDriveLetter = "D" or whatever your default CD / DVD ROM drive is.
Works like a charm
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
|