CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2005
    Posts
    63

    callback functions

    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:
    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)
    {
    ...
    ..
    ...
    }
    This callback function is used here:
    Code:
    returnValue = emuInit(recvPacket_callback,maxPacketSize,ID,maxNumNodes);
    I have also tried these without success giving the same error:
    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);
    emuInit is declared as follows:
    Code:
    int filterPacket::init(int (*callbackFunction)(unsigned char *, int), int maxBytes, unsigned char id, int numNodes)
    I am getting this error from ms visual studio 2006:
    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

  2. #2
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,150

    Re: callback functions

    Because you have:
    Code:
    int filterPacket::init(int  (*callbackFunction)(unsigned char *, int), ...
    and you actual callback is:
    Code:
    void  aodv_rit::recvPacket_callback(unsigned char *packet, int size)
    The return type doesn't match.
    Marc Gregoire - NuonSoft (http://www.nuonsoft.com)
    My Blog
    Wallpaper Cycler 3.5.0.97

    Author of Professional C++, 4th Edition by Wiley/Wrox (includes C++17 features)
    ISBN: 978-1-119-42130-6
    [ http://www.facebook.com/professionalcpp ]

  3. #3
    Join Date
    Jan 2005
    Posts
    63

    Re: callback functions

    Sweet thanks for the help.
    Amish

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured