Re: Callbacks in C libraries
Re: Callbacks in C libraries
- Subject: Re: Callbacks in C libraries
- From: Bill Cheeseman <email@hidden>
- Date: Sat, 14 Jun 2003 17:08:19 -0400
on 03-06-14 4:48 PM, Eric Shepherd at email@hidden wrote:
>
I have a Cocoa application that needs to use an ANSI C library. One of
>
the functions I need to call requires as a parameter a pointer to a
>
callback function that gets called periodically with the results of the
>
operation. The callback needs to be a function with the prototype:
>
>
int CallbackFunc(ConfigRec *cfgRec, const DataRec *pRecord);
>
>
How can my Objective C class use this C library function, providing a
>
pointer to the callback function, and have the callback still able to
>
access member data within my Objective C class?
This is often done by passing self in a userInfo parameter to the function,
so that code within the function can refer to self and its instance
variables and accessors. If pRecord in your callback function is equivalent
to a Carbon userInfo parameter, you're all set. Otherwise, you might have to
use a global static variable, or something like that.
--
Bill Cheeseman - email@hidden
Quechee Software, Quechee, Vermont, USA
http://www.quecheesoftware.com
The AppleScript Sourcebook -
http://www.AppleScriptSourcebook.com
Vermont Recipes -
http://www.stepwise.com/Articles/VermontRecipes
_______________________________________________
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.