• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Passing Obj-C method as callback to C function
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Passing Obj-C method as callback to C function


  • Subject: Passing Obj-C method as callback to C function
  • From: email@hidden
  • Date: Tue, 28 Oct 2003 14:58:41 -0000

Hi all,

I have a library written in C which implements a function to provide
background notification of events.

Is it possible to pass an Obj-C object method pointer/selector/whatever to
my C function to allow the library to perform it's callback.


// header:

typedef int (*FUNC_ENUM_CALLBACK)(void *);
int EnumerateStuff( FUNC_ENUM_CALLBACK pCallback, void *pContext );

// lib source:
int EnumerateStuff( FUNC_ENUM_CALLBACK pCallback, void *pContext )
{
pCallback(pContext);
return 0;
}


What I currently have is a C function implemented outside the Obj-C class
which receives a pointer to the Obj-C object as the context pointer, it uses
this pointer to enable access to the object methods for handling the
callback.
Is it possible to have the callback in the object itself.

Thanks

Alun Carp
Driver Development Team Leader
Data Encryption Systems Limited
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: Passing Obj-C method as callback to C function
      • From: Bill Cheeseman <email@hidden>
    • Re: Passing Obj-C method as callback to C function
      • From: Stéphane Sudre <email@hidden>
    • Re: Passing Obj-C method as callback to C function
      • From: Ambroise Confetti <email@hidden>
    • Re: Passing Obj-C method as callback to C function
      • From: "Alastair J.Houghton" <email@hidden>
  • Prev by Date: Re: What is this error?
  • Next by Date: Re: What is the maximum size of an NSString?
  • Previous by thread: Re: What is this error?
  • Next by thread: Re: Passing Obj-C method as callback to C function
  • Index(es):
    • Date
    • Thread