the following code is writen for recording sounds;
but the audio device can't open .
why is this happened. please help me!
and you can correct the code in my program.
thank you very much!!!
the following code is what i have writen.


DWORD CMainFrame::recordsound(DWORD time)
{

DWORD dwReturn;
UINT wDeviceID;
MCI_OPEN_PARMS mciOpenParms;
MCI_RECORD_PARMS mciRecordParms;
MCI_SAVE_PARMS mciSaveParms;

CString filename;
CString filt="WAVE File (*.WAV)|*.wav|All files (*.*)|*.*||";

// OPENFILENAME - so i can get to its Help page easily

CFileDialog fileDlg(false,"*.wav","ÎÞ±êÌâ.wav",NULL,filt,this);
fileDlg.m_ofn.Flags|=OFN_FILEMUSTEXIST;
fileDlg.m_ofn.lpstrTitle="±£´æÎļþ";

if (fileDlg.DoModal()!=IDOK)
return 0;

filename=fileDlg.GetPathName();

mciOpenParms.lpstrElementName = "";
mciOpenParms.lpstrDeviceType="MCI_DEVTYPE_WAVEFORM_AUDIO";
if (dwReturn = mciSendCommand(0, MCI_OPEN,
MCI_OPEN_ELEMENT | MCI_OPEN_TYPE,
(DWORD)(LPVOID) &mciOpenParms)) {

// Failed to open device; don't close it, just return error.
MessageBox("Can't open the audio device!" ,MB_OK );
}
// The 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-audio device
// (milliseconds).
mciRecordParms.dwTo = time;
if (dwReturn = mciSendCommand(wDeviceID, MCI_RECORD,
MCI_TO | MCI_WAIT, (DWORD)(LPVOID) &mciRecordParms))
{
mciSendCommand(wDeviceID, MCI_CLOSE, 0, NULL);
MessageBox("Can't open the record device !",MB_OK );
} // Play the recording and query user to save the file.
if (MessageBox( "Do you want to save this recording?",
"", MB_YESNO) == IDNO) {
mciSendCommand(wDeviceID, MCI_CLOSE, 0, NULL);
return (0L); }
// Save the recording to a file named TEMPFILE.WAV. Wait for
// the operation to complete before continuing.
mciSaveParms.lpfilename = LPCSTR (filename);
if (dwReturn = mciSendCommand(wDeviceID, MCI_SAVE,
MCI_SAVE_FILE | MCI_WAIT, (DWORD)(LPVOID) &mciSaveParms))
{ mciSendCommand(wDeviceID, MCI_CLOSE, 0, NULL);
return (dwReturn);
}

}

MR kingwgl
please write to me kingwgl@263.net