Re: Interfacing cocoa/obj-c within a C plug-in API
Re: Interfacing cocoa/obj-c within a C plug-in API
- Subject: Re: Interfacing cocoa/obj-c within a C plug-in API
- From: Uli Kusterer <email@hidden>
- Date: Tue, 22 Dec 2009 11:41:12 +0100
On 22.12.2009, at 00:22, Rich E wrote:
> I learn best by examples, does anyone know of any existing C applications
> that make use of Cocoa or Objective-C? Else, any advice on how to combine
> these two with a host written in C?
As Graham said, since Objective C is based on plain C (even more so than C++, which, among other things, applies name mangling to functions unless you explicitly mark them as 'extern "C"'), it's fairly straightforward. Just make sure that the C functions the host application calls in your plug-in only take C types as parameters. But the plugin protocols usually do that already, so no worry.
If you need to export a header to some C-only caller, you can use # if __OBJC__ to make sure it doesn't see any of your ObjC constructs (just like you would use #if __cplusplus to hide C++ constructs).
The only issues you may have are Carbon/Cocoa integration issues, where the frameworks have different ways of doing things. E.g. it's not easy to put Cocoa sheets on Carbon windows or vice versa. You may want to look into Apple"s documentation, to make sure you take care of the staples, like
- Call NSApplicationLoad()
- catch any ObjC exceptions so they don't waltz through the C code
- Create the requisite autorelease pools
Cheers,
-- Uli Kusterer
"The witnesses of TeachText are everywhere..."
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden