Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Callback problem

Status
Not open for further replies.

Markclee

Programmer
Apr 19, 2005
2
US
I'm having trouble setting up a callback function. I have a class ClassA that is instantiating another class ClassB.

ClassB's header has:
typedef void ( CALLBACK* MSGPROC ) ( void*, char*, int );
void SetCallback( MSGPROC pFunction, void* pValue ) { m_pCBFunction = pFunction; m_pCBArg = pValue; }

ClassA's header has:
void (*lpFunc) ( void* p, char* vstrMsg, int vnSrcConnectId );
void CALLBACK MessageReceived( void* p, char* vstrMsg, int vnSrcConnectId );

ClassA's cpp file has:
void CALLBACK ClassA::MessageReceived( void* p, char* vstrMsg, int vnSrcConnectId )

When I try to compile, I get:
error C2440: '=' : cannot convert from 'void (__stdcall CMachMonitor::* )(void *,char *,int)' to 'void (__cdecl *)(void *,char *,int)'
There is no context in which this conversion is possible

Can someone tell me what I'm doing wrong?
 
Oops, forgot that in classA's cpp file, I'm also assigning:

lpFunc = MessageReceived;

Any help would be appreciated. Thanks.
 
You can't assign a pointer to a non-static member function to a pointer to an ordinal function (it's your callback func pointer type).

Every call of a member function must get a pointer to an appropriate class object (to initialize this pointer). Obviously, a pointer to an ordinal function does not know anything about pointers to objects...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top