Recording to a wav file

Using D3, how do you record to a wav file? Am using a TMediaPlayer to play a CD
but want to save/record about 10 sec of a track to a wav file. Have tried using
a second TMediaPlayer but can't seem to get it to work (just keeps coming up
with errors). Got some example code from the Win32 API hlp and changed it over
for Delphi but it can't open the MCI device either???

Chris
c8...@aol.com

--------code from hlp file-------------------------

{
The following example function opens a waveform audio device with a new file,
records for the specified time, plays the recording, and prompts the user to
specify whether the recording should be saved as a file.

/*
 * Uses the MCI_OPEN, MCI_RECORD, MCI_SAVE commands to record and
 * save a waveform audio file. Returns 0L on success; otherwise,
 * returns an MCI error code.
 */

Quote
}

function TForm1.recordWAVEFile(dwMilliSeconds: WORD): WORD;
var
    wDeviceID : longint;
    dwReturn : WORD;
    mciOpenParms   : TMCI_OPEN_PARMS;
    mciRecordParms : TMCI_RECORD_PARMS;
    mciSaveParms   : TMCI_SAVEPARMS;
    mciPlayParms   : TMCI_PLAY_PARMS;
begin
    // Open a waveform device with a new file for recording.
    mciOpenParms.lpstrDeviceType := 'waveaudio';
    mciOpenParms.lpstrElementName := '';
    dwReturn := mciSendCommand(0, MCI_OPEN,
               MCI_OPEN_ELEMENT OR MCI_OPEN_TYPE,
               WORD(@mciOpenParms));
    if dwReturn <> 0
            //Failed to open device. Don't close it; just return error.
        then begin result := dwReturn; exit; end;

    // Device opened successfully. Get the device ID. */
    wDeviceID := mciOpenParms.wDeviceID;

    {
     * Begin recording and record for the specified number
     * of milliseconds. Wait for recording to complete before
     * continuing. Assume the default time format for the
     * waveform device (milliseconds).
     }
    mciRecordParms.dwTo := dwMilliSeconds;
    dwReturn := mciSendCommand(wDeviceID, MCI_RECORD,
            MCI_TO OR MCI_WAIT, WORD(@mciRecordParms));
    if dwReturn <> 0 then
        begin
          mciSendCommand(wDeviceID, MCI_CLOSE, 0, NULL);
          result := dwReturn;
        end;

    // Play the recording and query user to save the file. */
    mciPlayParms.dwFrom := 0;
    dwReturn := mciSendCommand(wDeviceID, MCI_PLAY,
            MCI_FROM OR MCI_WAIT, WORD(@mciPlayParms));
        if dwReturn <> 0 then begin
        mciSendCommand(wDeviceID, MCI_CLOSE, 0, NULL);
        result := dwReturn;
        exit;
        end;

    if MessageDlg('Do you want to save this recording?',mtConfirmation,
                  [mbYes,mbNo],0) = mrNo then begin
                    mciSendCommand(wDeviceID, MCI_CLOSE, 0, NULL);
                    result := 0;
                    exit;
                  end;
    {
     * Save the recording to a file named TEMPFILE.WAV. Wait for
     * the operation to finish before continuing.
    }
    mciSaveParms.lpfilename := 'tempfile.wav';
    dwReturn := mciSendCommand(wDeviceID, MCI_SAVE,
                MCI_SAVE_FILE OR MCI_WAIT,
                WORD(@mciSaveParms));
        if dwReturn <> 0 then begin
        mciSendCommand(wDeviceID, MCI_CLOSE, 0, NULL);
        result := dwReturn;
        end;

    result := 0;
end;

--------------------------------------------------------