Simonkale
July 18th, 2001, 07:37 AM
What information is returned by "status" command of mciCommand when called with mciSendString?
I have called:
NoError = mciSendString("status cdaudio media present", RS, len(RS), 0)
As written in MM reference:
Return Values
Returns information in the lpstrReturnString parameter of mciSendString. The information is dependent on the request type.
So what kind of return value should I expect?
Cimperiali
July 18th, 2001, 09:56 AM
From Api-guide:
Returns zero if successful or an error otherwise. The low-order word of the returned doubleword value contains the error return value. If the error is device-specific, the high-order word of the return value is the driver identifier; otherwise, the high-order word is zero. For a list of possible error values, see Constants: MCIERR Return Values.
To retrieve a text description of mciSendString return values, pass the return value to the mciGetErrorString function.
The mciGetErrorString function retrieves a string that describes the specified MCI error code.
Example:
private Const MCI_OPEN = &H803
private Const MCI_OPEN_TYPE = &H2000&
private Const MCI_OPEN_SHAREABLE = &H100&
private Const MCI_SET = &H80D
private Const MCI_SET_DOOR_OPEN = &H100&
private Const MCI_CLOSE = &H804
private Type MCI_OPEN_PARMS
dwCallback as Long
wDeviceID as Long
lpstrDeviceType as string
lpstrElementName as string
lpstrAlias as string
End Type
private Declare Function mciSendCommand Lib "winmm.dll" Alias "mciSendCommandA" (byval wDeviceID as Long, byval uMessage as Long, byval dwParam1 as Long, byref dwParam2 as Any) as Long
private Declare Function mciGetErrorString Lib "winmm.dll" Alias "mciGetErrorStringA" (byval dwError as Long, byval lpstrBuffer as string, byval uLength as Long) as Long
Dim openParams as MCI_OPEN_PARMS
private Sub Form_Load()
'KPD-Team 2001
'URL: http://www.allapi.net/
'KPDTeam@Allapi.net
Dim lRet as Long
'initialize the structure
openParams.wDeviceID = 0
openParams.lpstrDeviceType = "cdaudio"
'get the device ID
lRet = mciSendCommand(0, MCI_OPEN, MCI_OPEN_TYPE Or MCI_OPEN_SHAREABLE, openParams)
'check for error
If lRet <> 0 then
'show error
MsgBox GetMCIErrorString(lRet), vbCritical
else
'open the door of the CD-ROM drive
lRet = mciSendCommand(openParams.wDeviceID, MCI_SET, MCI_SET_DOOR_OPEN, byval 0&)
'check for errors
If lRet <> 0 then MsgBox GetMCIErrorString(lRet), vbCritical
End If
'clean up
mciSendCommand openParams.wDeviceID, MCI_CLOSE, 0, byval 0&
End Sub
private Function GetMCIErrorString(lErr as Long) as string
'create a buffer
GetMCIErrorString = Space$(255)
'retrieve the error string
mciGetErrorString lErr, GetMCIErrorString, len(GetMCIErrorString)
'strip off the trailing spaces
GetMCIErrorString = Trim$(GetMCIErrorString)
End Function
(I did not tested this, just copy and paste from Api-guide - a free tool)
Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, Bruno Paris and all the other wonderful people who made and make Codeguru a great place. Come back soon, you Gurus.