Dear Antonio.
There wasn't any error after I add the "CLASSDATA lRegistered AS LOGICAL" Code.
But the HandleEvent did not run.
Attached is my source code.
Code: Select all
#include "Fivewin.ch"
#define MM_WOM_OPEN 955 /* waveform output */
#define MM_WOM_CLOSE 956
#define MM_WOM_DONE 957
#define MM_WIM_OPEN 958 /* waveform input */
#define MM_WIM_CLOSE 959
#define MM_WIM_DATA 960
STATIC oWave
Function Main()
LOCAL oWnd
DEFINE WINDOW oWnd FROM 3, 6 TO 20, 70 ;
TITLE "Voice Recoder Test"
SetKey( VK_F2, { || StartWave( oWnd ), RecordWave( oWnd ) } )
ACTIVATE WINDOW oWnd ;
VALID App_Exit()
Return NIL
//---------------------------------------------------------------------------//
Function StartWave( oWnd )
oWave := TSipWave():New( oWnd )
Return NIL
//---------------------------------------------------------------------------//
Function RecordWave( oWnd )
oWave:WaveInStart( oWnd )
Return NIL
//---------------------------------------------------------------------------//
Function App_Exit()
LOCAL lResult := .F.
if MsgYesNo( "Are you sure?", "Do you want to exit?" )
lResult := .T.
if oWave != NIL
oWave:WaveInStop()
oWave:WaveInClose()
oWave:End()
endif
endif
Return lResult
//---------------------------------------------------------------------------//
CLASS TSipWave FROM TControl
DATA hWaveIn
DATA hWaveOut
DATA aBuffer AS ARRAY INIT Array(2)
DATA aWaveHdr AS ARRAY INIT Array(2)
CLASSDATA lRegistered AS LOGICAL
METHOD New( oWnd ) CONSTRUCTOR
METHOD WaveInStart( oWnd )
METHOD WaveInStop() INLINE HB_WaveInStop( ::hWaveIn )
METHOD WaveInClose() INLINE HB_WaveInClose( ::hWaveIn )
METHOD End() INLINE ::Destory()
METHOD Destory()
METHOD HandleEvent( nMsg, nWParam, nLParam )
ENDCLASS
//---------------------------------------------------------------------------//
METHOD New( oWnd ) CLASS TSipWave
DEFAULT oWnd := GetWndDefault()
::nId = ::GetNewId()
::oWnd = oWnd
::nStyle = nOR( WS_CHILD, WS_VISIBLE )
::Register()
if !Empty( oWnd:hWnd )
::Create()
oWnd:AddControl( Self )
else
oWnd:DefControl( Self )
endif
::aBuffer[1] := HB_WaveInitBuffer()
::aBuffer[2] := HB_WaveInitBuffer()
RETURN Self
//---------------------------------------------------------------------------//
METHOD WaveInStart( oWnd ) CLASS TSipWave
LOCAL hWaveIn
if HB_WaveInOpen( @hWaveIn, oWnd:hWnd ) >= 0
::hWaveIn := hWaveIn
::aWaveHdr[1] := HB_InitWaveHdr( ::aBuffer[1] )
::aWaveHdr[2] := HB_InitWavehdr( ::aBuffer[2] )
if HB_WaveInPrepareHeader( ::hWaveIn, ::aWaveHdr[1] ) < 0
MsgAlert( "WaveInPrepareHeader Error" )
endif
if HB_WaveInPrepareHeader( ::hWaveIn, ::aWaveHdr[2] ) < 0
MsgAlert( "WaveInPrepareHeader Error" )
endif
if HB_WaveInAddBuffer( ::hWaveIn, ::aWaveHdr[1] ) < 0
MsgAlert( "WaveInAddBuffer Error" )
endif
if HB_WaveInAddBuffer( ::hWaveIn, ::aWaveHdr[2] ) < 0
MsgAlert( "WaveInAddBuffer Error" )
endif
if HB_WaveInStart( ::hWaveIn ) >= 0
// To do
endif
endif
Return NIL
//---------------------------------------------------------------------------//
METHOD Destory() CLASS TSipWave
HB_WaveFreeBuffer( ::aBuffer[1] )
HB_WaveFreeBuffer( ::aBuffer[2] )
Return NIL
//---------------------------------------------------------------------------//
METHOD HandleEvent( nMsg, nWParam, nLParam ) CLASS TSipWave
do case
case nMsg == MM_WIM_OPEN
Msginfo( "MM_WIM_OPEN" )
case nMsg == MM_WIM_DATA
MsgInfo( "MM_WIM_DATA" )
case nMsg == MM_WIM_CLOSE
MsgInfo( "MM_WIM_CLOSE" )
endcase
Return Super:HandleEvent( nMsg, nWParam, nLParam )
//---------------------------------------------------------------------------//
#pragma BEGINDUMP
#include "hbapi.h"
#include "hbapiitm.h"
#include "hbdefs.h"
#include <windows.h>
#include <mmsystem.h>
#define BUFFER_SIZE 5000
HB_FUNC( HB_WAVEINITBUFFER )
{
PBYTE pBuffer;
pBuffer = hb_xgrab( BUFFER_SIZE );
hb_retptr( pBuffer );
}
//---------------------------------------------------------------------------//
HB_FUNC( HB_WAVEFREEBUFFER ) // BYTE pBuffer
{
hb_xfree( hb_parptr( 1 ) );
}
//---------------------------------------------------------------------------//
HB_FUNC( HB_INITWAVEHDR ) // BYTE pBuffer
{
PWAVEHDR pWavehdr;
pWavehdr = hb_xgrab( sizeof( WAVEHDR ) );
pWavehdr->lpData = (LPSTR) hb_parptr(1);
pWavehdr->dwBufferLength = BUFFER_SIZE;
pWavehdr->dwUser = 0;
pWavehdr->dwFlags = 0;
hb_retptr( pWavehdr );
}
//---------------------------------------------------------------------------//
HB_FUNC( HB_WAVEINOPEN ) // hWaveIn, pWavehdr, hWnd
{
HWAVEIN hWaveIn ;
WAVEFORMATEX waveformat;
int nResult;
waveformat.wFormatTag = WAVE_FORMAT_PCM;
waveformat.nChannels = 1;
waveformat.nBlockAlign = 1;
waveformat.wBitsPerSample = 8;
waveformat.nSamplesPerSec = 11025;
waveformat.nAvgBytesPerSec = 11025;
waveformat.cbSize = 0;
nResult = waveInOpen( &hWaveIn, WAVE_MAPPER, (LPWAVEFORMATEX)&waveformat, (DWORD)hb_parnl(2), 0, CALLBACK_WINDOW );
hb_stornl( (LONG)hWaveIn, 1 );
hb_retni( nResult );
}
//---------------------------------------------------------------------------//
HB_FUNC( HB_WAVEINPREPAREHEADER ) // hWaveIn, pWavehdr
{
hb_retni( waveInPrepareHeader( (HWAVEIN) hb_parnl(1), hb_parptr(2), sizeof( WAVEHDR ) ) );
}
//---------------------------------------------------------------------------//
HB_FUNC( HB_WAVEINUNPREPAREHEADER ) // hWaveIn, pWavehdr
{
hb_retni( waveInUnprepareHeader( (HWAVEIN) hb_parnl(1), hb_parptr(2), sizeof( WAVEHDR ) ) );
}
//---------------------------------------------------------------------------//
HB_FUNC( HB_WAVEINADDBUFFER ) // hWaveIn, pWavehdr
{
hb_retni( waveInAddBuffer( (HWAVEIN) hb_parnl(1), hb_parptr(2), sizeof( WAVEHDR ) ) );
}
//---------------------------------------------------------------------------//
HB_FUNC( HB_WAVEINSTART ) // hWaveIn
{
hb_retni( waveInStart( (HWAVEIN) hb_parnl(1) ) );
}
//---------------------------------------------------------------------------//
HB_FUNC( HB_WAVEINRESET ) // hWaveIn
{
hb_retni( waveInReset( (HWAVEIN) hb_parnl(1) ) );
}
//---------------------------------------------------------------------------//
HB_FUNC( HB_WAVEINSTOP ) // hWaveIn
{
hb_retni( waveInStop( (HWAVEIN) hb_parnl(1) ) );
}
//---------------------------------------------------------------------------//
HB_FUNC( HB_WAVEINCLOSE ) // hWaveIn
{
hb_retni( waveInClose( (HWAVEIN) hb_parnl(1) ) );
}
//---------------------------------------------------------------------------//
#pragma ENDDUMP
oknbs.