加入如下的声明后就能引用这个API函数:
Private Declare Function CDdoor Lib "winmm.dll" Alias "mciSendStringA" _
( _
ByVal lpstrCommand As String, _
ByVal lpstrReturnString As String, _
ByVal uReturnLength As Long, _
ByVal hwndCallback As Long _
) As Long
引用的语法是:
Call CDdoor("set CDAudio door closed", 0, 0, 0) '用以关闭光驱门
Call CDdoor("set CDAudio door open", 0, 0, 0) '用以打开光驱门
程序中使用了一个布尔型变量来标示当前光驱门开与关的状态。
如果配合检测光驱是否存在的函数一起使用,此程序的通用性会更高。而关于检测驱动
器信息的函数GetDriveType,GetLogicalDrives,我们会在另外一个实例中介绍。
或用下方法:
声明 :
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
代码 :
Sub OpenCDDoor()
mciSendString "Set CDAudio Door Open Wait", 0&, 0&, 0&
End Sub
Sub CloseCDDoor()
mciSendString "Set CDAudio Door Closed Wait", 0&, 0&, 0&
End Sub |