• 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: Callbacks in C libraries
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

References: 
 >Callbacks in C libraries (From: Eric Shepherd <email@hidden>)

  • Prev by Date: Callbacks in C libraries
  • Next by Date: Re: Really confused about "bounds" and "frames".
  • Previous by thread: Callbacks in C libraries
  • Next by thread: Re: Callbacks in C libraries
  • Index(es):
    • Date
    • Thread