• 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
Re: Passing Obj-C method as callback to C function
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Passing Obj-C method as callback to C function


  • Subject: Re: Passing Obj-C method as callback to C function
  • From: Stéphane Sudre <email@hidden>
  • Date: Tue, 28 Oct 2003 16:46:53 +0100

I'm wondering if this might not work.

You can get the C function pointer corresponding to an ObjC method since we're still dealing with C.

typedef int (*myMethodIMP)(id, void *); /* Not sure about this point, it's a SEL in fact instead of a void *) */
myMethodIMP tMethodIMP;

myMethodIMP =(myMethodIMP) [self methodForSelector:@selector(mySelector)];


In the C code.

tResult= myMethodIMP(myObjectiveCObjectObject,tSelector);


On Tuesday, October 28, 2003, at 03:58 PM, email@hidden wrote:

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.
_______________________________________________
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.

References: 
 >Passing Obj-C method as callback to C function (From: email@hidden)

  • Prev by Date: Re: What is this error?
  • Next by Date: Re: Disk Copy
  • Previous by thread: Re: Passing Obj-C method as callback to C function
  • Next by thread: Re: Passing Obj-C method as callback to C function
  • Index(es):
    • Date
    • Thread