Re: Call back from C++ code.
Re: Call back from C++ code.
- Subject: Re: Call back from C++ code.
- From: Nicko van Someren <email@hidden>
- Date: Wed, 29 Mar 2006 15:05:06 +0100
On 29 Mar 2006, at 14:34, innovator information wrote:
I am using Obj-C for Cocoa development.
And my library is C++. I am using C++ very comfortably with Obj-C.
I want a callback function for a Obj-C object from C++ class.
How can I call a Obj-C function from C++ ?
There are two ways to do this. One is to read up on Objective C++,
[1] which is a bit of a car crash between Objective C and C++. You
can then write the code in a file with the .mm. Alternatively, if
you don't need to do a huge amount of code and you already have C++
and Objective-C working happily in your application you can use the
fact that regular C functions which exist in .m files can send
Objective C messages. Thus you can write a function like this:
void tell_thing_to_to_foo(void *thingptr) {
[(Thing *) thingptr foo];
}
Ifyou declare this as a regular C function in a header file then it
can then be called as a plain-old-C callback from your C++ code.
Nicko
[1] http://developer.apple.com/documentation/Cocoa/Conceptual/
ObjectiveC/Articles/chapter_4_section_10.html
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden