Photon has never been very C++ friendly. Which is unfortunate because is
essentially very object oriented itself.
Nonetheless, (and who the hell made up that word?), you can call C++ methods
from Photon callbacks.
The first problem is that Photon won’t use a ‘this’ pointer for you. So,
the first step is to write static method cover functions into your class for
any class methods that you want to call.
I.E.
class myclass
{
public:
void fn_X();
static void fn_X_cover( myclass * mcPtr );
};
static void myclass::fn_X_cover( myclass * mcPtr )
{
mcPtr->fn_X(); // this line fakes a this pointer
};
This way your photon code can call myclass::fn_X_cover( ) and pass in a
pointer to the object to be treated as this and your cover function will do
the call to the real C++ method with a real this.
The second gimmick is that when you tell photon the name of your callback
functions you need to make sure that they will be in a C++ module so that
all of the appropriate name mangling will happen and the linker can find
everything. You do this by adding a file name to the function name in a
callback in the callback editor.
I.E.
Instead of entering a callback function in the callback editor in PhAB as:
“my_callback()”, enter it as “my_callback()@my_callback.cc”. The ‘@’ tells
PhAB that your giving it the exact name of the file that has the function
and the .cc extension tells it that this is a C++ file.
Important Notes:
Make sure that you tell PhAB that your app is a C++ app before you generate
it the first time (by specifying at least one callback with “@*.cc”)
otherwise there will me many assumption that PhAB will make that are invalid
that you will have to hand fix.
Also, I’ve found that .cc works better than .cpp or .C file extensions. I
realize that this should be a matter of personal taste but the .cpp & .C
extensions have both exhibited problems at some point in a project life
cycle.
Good luck.
“Jordi Garcia” <jgbusquets@yahoo.com> wrote in message
news:abc7lu$8c9$1@inn.qnx.com…
Hi!!
I’m very new to Photon & QNX, so be patient… > > )
I’ve done my first steps in photon, and I have designed the interface of
my
application (in fact, just a window and a pair of buttons inside).
In the other hand I have 4 classes written in C++ (developed under unix)
that implement a genetic algorithm.
The big point now is that I want to use this classes in my project. For
example, I would like to call the algorithm when I press one of the
buttons
in my window.
Is this integration possible?? What steps do I have to follow?? Do I have
to
modify a ‘makefile’ or similar?? And the most important… will my c++
code
compile under photon??
Thanks all.
Jordi Garcia.