Calling Cocoa from C
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/