tbchambe
December 30th, 2002, 10:31 AM
I am trying to play wave audio data blocks with the low-level functions provided by Windows and declared in <mmsystem.h>. My problem is I can't get the compiler to allow the type cast from the Wave callback function pointer to DWORD, which the waveOutOpen() function expects for parameter 4. I have tried several ways, all without success:
Res = waveOutOpen( &WaveDevice, AudioDevice, &Wfmt, (DWORD)WaveCallback, 0UL, CALLBACK_FUNCTION);
Res = waveOutOpen( &WaveDevice, AudioDevice, &Wfmt, reinterpret_cast<DWORD>(WaveCallback), 0UL, CALLBACK_FUNCTION);
Res = waveOutOpen( &WaveDevice, AudioDevice, &Wfmt, static_cast<DWORD>(WaveCallback), 0UL, CALLBACK_FUNCTION);
I have also tried casting to int, unsigned int, and (void *) with no success.
The MSDN documentation says I should be able to cast from any pointer type to any integral type using reinterpret_cast, but it doesn't work. Is this a bug? Is there a workaround? Here is the error message the compiler gives:
-------------------------------------
D:\TOM\Code\DAWin\DAWinDlg.cpp(356) : error C2440: 'reinterpret_cast' : cannot convert from 'void (__stdcall CDAWinDlg::*)(struct HWAVEOUT__ *,unsigned int,unsigned long,unsigned long,unsigned long)' to 'unsigned long'.
Conversion is a valid standard conversion, which can be performed implicitly or by use of static_cast, C-style cast or function-style cast.
-------------------------------------
The message is similar regardless of how I try to do the type cast. What is a “function-style” cast?
Res = waveOutOpen( &WaveDevice, AudioDevice, &Wfmt, (DWORD)WaveCallback, 0UL, CALLBACK_FUNCTION);
Res = waveOutOpen( &WaveDevice, AudioDevice, &Wfmt, reinterpret_cast<DWORD>(WaveCallback), 0UL, CALLBACK_FUNCTION);
Res = waveOutOpen( &WaveDevice, AudioDevice, &Wfmt, static_cast<DWORD>(WaveCallback), 0UL, CALLBACK_FUNCTION);
I have also tried casting to int, unsigned int, and (void *) with no success.
The MSDN documentation says I should be able to cast from any pointer type to any integral type using reinterpret_cast, but it doesn't work. Is this a bug? Is there a workaround? Here is the error message the compiler gives:
-------------------------------------
D:\TOM\Code\DAWin\DAWinDlg.cpp(356) : error C2440: 'reinterpret_cast' : cannot convert from 'void (__stdcall CDAWinDlg::*)(struct HWAVEOUT__ *,unsigned int,unsigned long,unsigned long,unsigned long)' to 'unsigned long'.
Conversion is a valid standard conversion, which can be performed implicitly or by use of static_cast, C-style cast or function-style cast.
-------------------------------------
The message is similar regardless of how I try to do the type cast. What is a “function-style” cast?