#include <Windows.h>
//#include <afxtempl.h>
//#include <stack>
#pragma comment (lib, "Winmm")
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <iomanip>
#include <climits>
#include <ostream>
using namespace std;
int text_buf_size = 50;
int _SIZE = 16384;
LRESULT FAR PASCAL WndProc (HWND hWnd, UINT msg, WPARAM wParam,
LPARAM lParam)
{
switch (msg)
{
case MM_WIM_DATA:
cout<<"WORK!"<<endl;
// A waveform audio data block has been played and can now be
// freed.
waveOutUnprepareHeader ((HWAVEOUT)wParam, (LPWAVEHDR)lParam,
sizeof (WAVEHDR));
// Free hData memory
waveOutClose ((HWAVEOUT)wParam);
break;
}
return DefWindowProc (hWnd, msg, wParam, lParam);
}
static void aps()
{
int dfghy = 7;
cout<<"AAAAAAAAAAAAAAA";
}
int main()
{
LPWSTR st = new WCHAR[text_buf_size] ;
memset(st,0,text_buf_size);
HWAVEOUT m_hOutDev = NULL;
WAVEHDR *phdrNew = (WAVEHDR *) malloc (sizeof (WAVEHDR)) ;
memset (phdrNew, 0, sizeof (WAVEHDR)) ;
MMRESULT mmr ;
MMRESULT Error_chek ;
WAVEFORMATEX wfe ;
HANDLE f = CreateFile((L"c:\\1.wav"), GENERIC_READ, NULL, NULL, OPEN_EXISTING, NULL, NULL);
//BYTE* pBuffer = new BYTE[_SIZE];
char* pBuffer = new char[_SIZE];
DWORD rw = 0;
ReadFile(f, pBuffer, _SIZE, &rw, NULL);
wfe.nChannels = 1 ;
wfe.wBitsPerSample = 16 ;
wfe.nSamplesPerSec = 8000 ;
wfe.wFormatTag = WAVE_FORMAT_PCM ;
wfe.nBlockAlign = wfe.nChannels * wfe.wBitsPerSample / 8 ;
wfe.nAvgBytesPerSec = wfe.nSamplesPerSec * wfe.nBlockAlign ;
wfe.cbSize = 0 ;
UINT c = waveOutGetNumDevs();
cout<<"waveOutOpen:"<<endl;
mmr = waveOutOpen(&m_hOutDev,WAVE_MAPPER,&wfe,(DWORD)WndProc, NULL, CALLBACK_FUNCTION );
phdrNew->dwFlags =0;
phdrNew->lpData = pBuffer;
phdrNew->dwBufferLength = _SIZE;
mmr = waveOutPrepareHeader(m_hOutDev,phdrNew ,sizeof (WAVEHDR));
if(mmr !=MMSYSERR_NOERROR)
{
cout<<"Error"<<endl;
}
mmr =waveOutWrite(m_hOutDev,phdrNew,sizeof (WAVEHDR));
Error_chek = waveOutGetErrorText(mmr,st,text_buf_size);
if(mmr !=MMSYSERR_NOERROR)
{
Error_chek = waveOutGetErrorText(mmr,st,text_buf_size);
cout<<"Error: ";
for(int i = 0;i< text_buf_size;i++)
{
if(st == 0)
break;
wcout<<st;
}
cout<<endl;
exit(1);
/*if(mmr !=WAVERR_UNPREPARED)
cout<<"Error in waveOutWrite: Header not prepeared"<<endl;
else
cout<<"Error in waveOutWrite"<<endl;*/
}
Sleep(1500);
mmr = waveOutUnprepareHeader(m_hOutDev,phdrNew ,sizeof (WAVEHDR));
if(mmr !=MMSYSERR_NOERROR)
{
cout<<"Error in waveOutUnprepareHeader"<<endl;
}
mmr =waveOutClose(m_hOutDev);
if(mmr !=MMSYSERR_NOERROR)
{
cout<<"Error in waveOutClose"<<endl;
}
Sleep(1000);
}
}
С++ Определение адреса отзыва
как правильно указать в ф-ии
[COLOR="Red"]waveOutOpen(&m_hOutDev,WAVE_MAPPER,&wfe,(DWORD)WndProc, NULL, CALLBACK_FUNCTION );[/COLOR]
4 параметр адрес ф-ии, а то так программу выкидывает.
Код:
Скорее всего, функция WndProc должна иметь соглашение о вызове stdcall, а не pascal