• 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
Calling Cocoa from C
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Calling Cocoa from C


  • Subject: Calling Cocoa from C
  • From: "Simon Stapleton" <email@hidden>
  • Date: Mon, 25 Jun 2001 15:59:57 +0100

Hi there.

A question. I know I can call C/C++ from cocoa, but can I do the reverse?

My problem is this.

I have an application which I want to port to Cocoa. It's written in C,
with a very nice platform-independent layer. However, the C 'engine'
expects to be able to output text.

I think I have a few possible solutions here:

1) Make a 'bridging' layer in Objective-C allowing the C engine to call
specific Cocoa functionality
2) Rewrite the guts of the platform-independent part in cocoa as well
as the platform-depenent part.
3) Do the whole damn thing in Carbon.

I don't want to do (3), (2) would bugger up the current implementations
on other platforms, and I'm not sure if (1) is even possible, although I
think it's my favoured approach.

I was thinking something like...

// raw C method to call the cocoa implementation
void os_write_text (char * text)
{
// Can I do this?
[[bridgeClass instance] cocoaWriteText:text];
}

@implementation bridgeClass

// Standard singleton type method
+ (bridgeClass *) instance
{
return _sharedInstance;
}

// Cocoa compositing code
- (void) cocoaWriteText: (char *) text
{
// Do the compositing here
}

@end

Would this work?

Of course, I'll have to get over the assumptions the application makes
for compositing, but that's another bridge to cross ;-)

Simon

--
Your mouse has moved. You must reboot Windows NT for these changes to be
recognised.

This message was sent by Easymail - http://www.easynet.co.uk/


  • Follow-Ups:
    • Re: Calling Cocoa from C
      • From: Peter Ammon <email@hidden>
    • Re: Calling Cocoa from C
      • From: John Pannell <email@hidden>
  • Prev by Date: Re: Confusion
  • Next by Date: Re: Confusion
  • Previous by thread: Vermont Recipes updated
  • Next by thread: Re: Calling Cocoa from C
  • Index(es):
    • Date
    • Thread