[program-l] Containing callback routines in C++ classes

  • From: "Tim Burgess" <tim@xxxxxxxxxxxxx>
  • To: <program-l@xxxxxxxxxxxxx>
  • Date: Mon, 12 Oct 2009 18:29:38 +0100

Hi,

I've a call back routine that works fine in the main module of a Win32
application.  However, if I turn it into a public member of a class then
refer to it from within another member function of the same class, it throws
the following error at compile time:

error C2440: 'type cast' : cannot convert from 'void (__stdcall
MCP::*)(struct HMIDIIN__ *,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 line of code that fails is:

if (!(err = midiInOpen( &myMIDIInDevice, iPortNumber, (DWORD)midiCallback,
0, CALLBACK_FUNCTION)))
        {

The actual fault seems to the the reference to the MIDICallback routine - a
friend of mine has suggested that this code is being referenced before it
exists within the compiler's v-table, but he lost me at that point and
couldn't suggest a work-around that didn't involve taking MIDICallback out
of the class module (something I'm trying to avoid, as there'll be derived
code from this base class later in the project).

Any takers?

Best wishes.

Tim Burgess
Raised Bar Ltd
Phone:  +44 (0)1827 719822
Mobile:  07989 486976
Web:  http://www.raisedbar.net
Facebook:
http://www.facebook.com/pages/Atherstone-United-Kingdom/Raised-Bar-Ltd/12023
4896800

Don't forget to vote for improved access to music and music technology at

http://www.raisedbar.net/petition.htm
 



** To leave the list, click on the immediately-following link:-
** [mailto:program-l-request@xxxxxxxxxxxxx?subject=unsubscribe]
** If this link doesn't work then send a message to:
** program-l-request@xxxxxxxxxxxxx
** and in the Subject line type
** unsubscribe
** For other list commands such as vacation mode, click on the
** immediately-following link:-
** [mailto:program-l-request@xxxxxxxxxxxxx?subject=faq]
** or send a message, to
** program-l-request@xxxxxxxxxxxxx with the Subject:- faq

Other related posts: