The error you posted in your comments indicates that waveOutProc
is a member function of the Audio
class and C++ will not allow you to assign a member function to a parameter or variable that expects a "normal" function. This is because member functions have an implicit parameter called this
which is a pointer to an Audio
class instance.
Instead it is considered good practice to write a so-called static member function (the static
keyword means that there is no implicit this
parameter) which wraps the member function you want to call. This is possible because waveOutOpen
takes a user-data variable as it's 5th parameter which is then passed to the static callback. A static member function wrapper is better than just making your callback static because you can then access all of your classes member variables (and not only one variable, for example freeBlockCounter
in your case). Your static member function wrapper could look like this:
class Audio {
private:
int freeBlockCounter;
public:
....
static void CALLBACK waveOutProcWrapper(HWAVEOUT hWaveOut, unsigned int uMsg,
unsigned long dwInstance,
unsigned long dwParam1,
unsigned long dwParam2);
void waveOutProc(HWAVEOUT hWaveOut, unsigned int uMsg, unsigned long dwParam1,
unsigned long dwParam2);
};
and implementation of the wrapperProc:
void CALLBACK Audio::waveOutProcWrapper(HWAVEOUT hWaveOut, unsigned int uMsg,
unsigned long dwInstance,
unsigned long dwParam1,
unsigned long dwParam2) {
((Audio*)dwInstance)->waveOutProc(hWaveOut, uMsg, dwParam1, dwParam2);
}
Notice how the dwInstance
parameter is "converted" to the implicit this
parameter. You can now supply waveOutProcWrapper
to waveOutOpen
int the following way:
if(waveOutOpen(
&hWaveOut,
WAVE_MAPPER,
&wfx,
(DWORD_PTR)waveOutProcWrapper, ///////////Error Point
(DWORD_PTR)this,
CALLBACK_FUNCTION) != MMSYSERR_NOERROR) {
fprintf(stderr, "unable to open wave mapper device\n");
ExitProcess(1);
}