Re: interfacing c++ -> cocoa/aqua
Re: interfacing c++ -> cocoa/aqua
- Subject: Re: interfacing c++ -> cocoa/aqua
- From: email@hidden
- Date: Sat, 7 Jul 2001 23:12:38 +0200
A friend and I are working on a project. We have some backend code in
C++. This code takes mouse and keyboard events, and spits out bitmaps.
We'd like to wrap a cocoa interface around it... Display the bitmaps in
an aqua window, and pass any mouse or keyboard events that occur in the
aqua window down to the c++ code.
How can we do this? Can we call c++ methods from cocoa? Can we call
cocoa methods from c++?
No you can't do that since Apple has not released ObjC++, yet.
But you can use C, since it's the basic language for ObjC and C++.
Just write headers file like this one:
#ifdef _cplusplus
extern "C" {
#endif
void myProcedure(int param);
int myFunction(double x, void* object);
#ifdef
}
#endif
Now you can #include the header from C++ AND ObjC files (thanks to the
tricky #ifdef...).
You have to implement each function in one of the two languages, which one
doesn't matter.
You can pass objects (either C++ or ObjC) as (void*) pointer, as in the
example, but it is more complicated to really use them in one language if
they have been created in the other: better avoid that.
This is done in more sophisticated way in the Commandant Project, see the
link below.
Thomas Lachand-Robert
********************** email@hidden
The Commandant Project:
http://lachand.free.fr/
<< Et le chemin est long du projet ` la chose. >> Molihre, Tartuffe.