CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    May 2009
    Posts
    2

    API defines public delegate.. huh?

    C# noob here. Wondering if anyone out there could shed some light on dealing with this API. I'm using .net 3.5.

    The API method is defined in the object browser as:
    public delegate int CallbackMessage(long userData, int nToolId, int nStatus, string pMessage)

    When I try the following code:
    CallbackMessage myCall = new CallbackMessage(); //i know this is wrong, looking at intellisense

    The intellisense on CallbackMessage constructor is telling me:
    CallbackMessage.CallbackMessage( int (long, int, int, string) target);

    How would I build a constructor for myCall? Thanks in advance.

  2. #2
    Join Date
    Sep 2008
    Location
    Netherlands
    Posts
    865

    Re: API defines public delegate.. huh?

    you need to something that looks like the next

    Code:
    private void myCallbackHandler(long userData, int nToolId, int nStatus, string pMessage){
      //do something with the values
    }
    
    private void Test(){
      //make a call to the API
      CallbackMessage.CallbackMessage += new CallbackMessage(myCallbackHandler);
    }

  3. #3
    Join Date
    May 2009
    Posts
    2

    Re: API defines public delegate.. huh?

    that worked.. thanks for the help!

  4. #4
    Join Date
    May 2007
    Posts
    1,546

    Re: API defines public delegate.. huh?

    You can also just write:

    Code:
    private void myCallbackHandler(long userData, int nToolId, int nStatus, string pMessage){
      //do something with the values
    }
    
    private void Test(){
      //make a call to the API
      CallbackMessage.CallbackMessage += myCallbackHandler;
    }
    www.monotorrent.com For all your .NET bittorrent needs

    NOTE: My code snippets are just snippets. They demonstrate an idea which can be adapted by you to solve your problem. They are not 100% complete and fully functional solutions equipped with error handling.

  5. #5
    Join Date
    Sep 2008
    Location
    Netherlands
    Posts
    865

    Re: API defines public delegate.. huh?

    Quote Originally Posted by Mutant_Fruit View Post
    You can also just write:

    Code:
    private void myCallbackHandler(long userData, int nToolId, int nStatus, string pMessage){
      //do something with the values
    }
    
    private void Test(){
      //make a call to the API
      CallbackMessage.CallbackMessage += myCallbackHandler;
    }
    Didn't know that :-)

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