I Try to make program Audio Recorder from LIne In / Microphone using C++ Builder.
I get 2 Error message :
- E2171 Body has already been defined for function '_fastcall TForm1::~TForm1()'
- E2188 Expression Syntax
Can somebody help me to finishing this problem ?
Here my Simple program :
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
#include "Vfw.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
extern HINSTANCE g_hInstance;
HANDLE m_hMCIWnd =NULL;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
m_hMCIWnd=MCIWndCreate(Handle,g_hInstance,WS_CHILD | WS_OVERLAPPED,NULL );
if ( NULL==m_hMCIWnd ) // error?
{
MessageBox(Handle,"Error Creating MCIWnd Window!",NULL, MB_OK);
return;
}
}
//-----------------------------------------------------------------
__fastcall TForm1::~TForm1(void)
{
MCIWndDestroy(m_hMCIWnd);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
// create new .WAV file
MCIWndNew(m_hMCIWnd, "waveaudio");
//----------------- Setting record ------------------------------------------
MCI_WAVE_SET_PARMS set_parms; // audio parameters
set_parms.wFormatTag = WAVE_FORMAT_PCM;
set_parms.wBitsPerSample = 16;
set_parms.nChannels = 1;
set_parms.nSamplesPerSec = 44100;
set_parms.nBlockAlign = (set_parms.nChannels*set_parms.wBitsPerSample)/8;
set_parms.nAvgBytesPerSec = ((set_parms.wBitsPerSample) *
set_parms.nChannels *
set_parms.nSamplesPerSec)/8;
// now send the format changes with MCI_SET
int deviceID=MCIWndGetDeviceID(m_hMCIWnd);
int result = mciSendCommand( deviceID, MCI_SET,
MCI_WAIT
| MCI_WAVE_SET_FORMATTAG
| MCI_WAVE_SET_BITSPERSAMPLE
| MCI_WAVE_SET_CHANNELS
| MCI_WAVE_SET_SAMPLESPERSEC
| MCI_WAVE_SET_AVGBYTESPERSEC
| MCI_WAVE_SET_BLOCKALIGN,
(DWORD)(LPVOID)&set_parms);
if ( result ) // failed?
{
char buffer[100];
mciGetErrorString(result, buffer, sizeof(buffer));
MessageBox( NULL, buffer, "MCI_WAVE_SET_1", MB_OK);
return;
}
//-----------------End Setting Record ---------------------------------------
// begin recording
MCIWndRecord(m_hMCIWnd);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
// stop recording and save file
MCIWndStop(m_hMCIWnd);
MCIWndSave(m_hMCIWnd,file);
MCIWndClose(m_hMCIWnd);
}
//---------------------------------------------------------------------------