API CD Player

CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More.

My CD Player will play musical CDs. Some built-in commands are play, pause, stop, rewind, fast forward, previous track, next track, open, close, and exit. I also added a combo box for easier track selection and a volume control to adjust volume.

Screen-shot

Some API calls it uses are:


Declare Function mciGetErrorString Lib "winmm.dll" Alias _
   "mciGetErrorStringA" _
   (byval dwError as Long, byval lpstrBuffer as string, _
    byval uLength as Long) as Long
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
'
public hmem as Long
'
public Const SND_ASYNC = &H1
public Const SND_NODEFAULT = &H2
public Const SND_PURGE = &H40
public Const SND_FILENAME = &H20000
'
public Const MMSYSERR_NOERROR = 0
public Const MAXPNAMELEN = 32
public Const MIXER_LONG_NAME_CHARS = 64
public Const MIXER_SHORT_NAME_CHARS = 16
public Const MIXER_GETLINEINFOF_COMPONENTTYPE = &H3&
public Const MIXER_GETCONTROLDETAILSF_VALUE = &H0&
public Const MIXER_SETCONTROLDETAILSF_VALUE = &H0&
public Const MIXER_GETLINECONTROLSF_ONEBYTYPE = &H2&
public Const MIXERLINE_COMPONENTTYPE_DST_FIRST = &H0&
public Const MIXERLINE_COMPONENTTYPE_SRC_FIRST = &H1000&
public Const MIXERLINE_COMPONENTTYPE_DST_SPEAKERS = _
               (MIXERLINE_COMPONENTTYPE_DST_FIRST + 4)
public Const MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE = _
               (MIXERLINE_COMPONENTTYPE_SRC_FIRST + 3)
public Const MIXERLINE_COMPONENTTYPE_SRC_LINE = _
               (MIXERLINE_COMPONENTTYPE_SRC_FIRST + 2)
public Const MIXERCONTROL_CT_CLASS_FADER = &H50000000
public Const MIXERCONTROL_CT_UNITS_UNSIGNED = &H30000
public Const MIXERCONTROL_CONTROLTYPE_FADER = _
               (MIXERCONTROL_CT_CLASS_FADER Or _
               MIXERCONTROL_CT_UNITS_UNSIGNED)
'
public Const MIXERCONTROL_CONTROLTYPE_VOLUME = _
               (MIXERCONTROL_CONTROLTYPE_FADER + 1)
'
public Type MIXERCONTROLDETAILS
    cbStruct    as Long
    dwControlID as Long
    cChannels   as Long
    item        as Long
    cbDetails   as Long
    paDetails   as Long
End Type
'
public Type MIXERCONTROLDETAILS_UNSIGNED
    dwValue as Long
End Type
'
public Type MIXERCONTROL
'
public Type MIXERLINE
'
'Allocates the specified number of bytes from the heap.
'
Declare Function GlobalAlloc Lib "kernel32" (byval _
    wFlags as Long, _
    byval dwBytes as Long) as Long
'
'Locks a global memory object and returns a pointer to the
' first byte of the object's memory block.  The memory block
' associated with a locked object cannot be moved or discarded.
'
Declare Function GlobalLock Lib "kernel32" (byval _
    hmem as Long) as Long
'
'Frees the specified global memory object and invalidates
'its handle.
'
Declare Function GlobalFree Lib "kernel32" (byval hmem as Long) _
    as Long
'
Declare Sub CopyPtrFromStruct Lib "kernel32" Alias _
    "RtlMoveMemory" _
    (byval ptr as Long, struct as Any, byval cb as Long)
'
Declare Sub CopyStructFromPtr Lib "kernel32" Alias "RtlMoveMemory" _
    (struct as Any, byval ptr as Long, byval cb as Long)
'
'Opens a specified mixer device and ensures that the
'device will not be removed until the application
'closes the handle.
'
Declare Function mixerOpen Lib "winmm.dll" _
    (phmx as Long, byval uMxId as Long, byval dwCallback as Long, _
    byval dwInstance as Long, byval fdwOpen as Long) as Long
'
'Sets properties of a single control associated with an
'audio line.
'
Declare Function mixerSetControlDetails Lib "winmm.dll" _
    (byval hmxobj as Long, pmxcd as MIXERCONTROLDETAILS, _
    byval fdwDetails as Long) as Long
'
'Retrieves information about a specific line of a mixer device.
'
Declare Function mixerGetLineInfo Lib "winmm.dll" _
    Alias "mixerGetLineInfoA" (byval hmxobj as Long, _
    pmxl as MIXERLINE, byval fdwInfo as Long) as Long
'
'Retrieves one or more controls associated with an audio line.
'
Declare Function mixerGetLineControls Lib "winmm.dll" _
    Alias "mixerGetLineControlsA" (byval hmxobj as Long, _
    pmxlc as MIXERLINECONTROLS, byval fdwControls as Long) _
    as Long
'
public Function fGetVolumeControl(byval hmixer as Long, _
        byval componentType as Long, byval ctrlType _
        as Long, _
        byref mxc as MIXERCONTROL) as Boolean
'

Download zipped project files (30k)

More by Author

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends & analysis

Must Read