Hi,
I have been trying to use callback functions without any success. I tried to follow the example B on this webpage:
http://www.newty.de/fpt/callback.html#member
Here is the code:
This callback function is used here:Code:class aodv_rit { public: static void recvPacket_callback(unsigned char *packet, int size); int recvPacket(unsigned char *packet, int size); } void aodv_rit::recvPacket_callback(unsigned char *packet, int size) { // explicitly cast to a pointer to TClassA aodv_rit* mySelf = (aodv_rit*) pt2Object; // call member mySelf->recvPacket(packet, size); } int aodv_rit::recvPacket(unsigned char * packet, int size) { ... .. ... }
I have also tried these without success giving the same error:Code:returnValue = emuInit(recvPacket_callback,maxPacketSize,ID,maxNumNodes);
emuInit is declared as follows:Code:returnValue = emuInit(&recvPacket_callback,maxPacketSize,ID,maxNumNodes); returnValue = emuInit(aodv_rit::recvPacket_callback,maxPacketSize,ID,maxNumNodes); returnValue = emuInit(&(aodv_rit::recvPacket_callback),maxPacketSize,ID,maxNumNodes);
I am getting this error from ms visual studio 2006:Code:int filterPacket::init(int (*callbackFunction)(unsigned char *, int), int maxBytes, unsigned char id, int numNodes)
error C2664: 'int (int (__cdecl *)(unsigned char *,int),int,unsigned char,int)' : cannot convert parameter 1 from 'overloaded-function' to 'int (__cdecl *)(unsigned char *,int)'
I am really confused about what could be wrong. I really hope some of the more knowledgeable people can help out. Thanks
Amish




Reply With Quote