comp.lang.ada
 help / color / mirror / Atom feed
* Importing and using a C++  class in Ada. Pragma Cpp_Constructor, Cpp_Class
       [not found] <20050505100047.AB84F4C40D0@lovelace.ada-france.org>
@ 2005-05-05 21:10 ` Christopher Gosset
  2005-05-06  3:20   ` Importing and using a C++ class in Ada. Pragma Cpp_Constructor,Cpp_Class Steve
                     ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Christopher Gosset @ 2005-05-05 21:10 UTC (permalink / raw)
  To: comp.lang.ada

I need to use some  classes from a DLL in my Ada app. I was hoping that
this was a straigthforward thing to do using pragma import and pragma
cpp_class and cpp_constructor. Is there a working example of this
somwhere. I am building the damn dll myself and I am also buliding the
damn .def file myself but the damn thing will still not work. Functions
that are not class members are no problem this works perfect! Are there
any tutorials, sample code available on this? As I see it this is far
from intuitive and its a major reason for NOT converting to ada. What I
would like is a simple "MS Visual Studio " like library brows tree
thing. So instead of having to "build a new operating system" to solve
even the most trivial task, such as calling a member function or a
constructor I could actually add a with clause or import clause and then
be able to see whats available in the lib. 

So if anyone has a working sample on the usage of these pragmas  I would
be more than happy.

I assume that the fact that there are no examples of the usage of these
Pragmas in the userguide or reference manual suggests that this is not
as straigth forward as advertised.  
/CG




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Importing and using a C++  class in Ada. Pragma Cpp_Constructor,Cpp_Class
  2005-05-05 21:10 ` Importing and using a C++ class in Ada. Pragma Cpp_Constructor, Cpp_Class Christopher Gosset
@ 2005-05-06  3:20   ` Steve
  2005-05-06  8:07   ` Importing and using a C++ class in Ada. Pragma Cpp_Constructor, Cpp_Class Adrien Plisson
                     ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Steve @ 2005-05-06  3:20 UTC (permalink / raw)


I have interfaced Ada with C++ classes, but the technique I used wasn't 
particularly pretty.

Before I say anything about that, have you considered making your C++ code 
into a COM object and then using GNATCOM to generate bindings to the object?

To make the not so pretty interface I set up a non-member equivalent for 
each method in the C++ class I wanted to call from Ada.  In addition to the 
arguments for the method, I explicitly passed the value of the "this" 
pointer of the object to the member function.  The member function would 
then turn around and call the member function via the this pointer.  Like I 
said, not pretty, but it works.

In the C++ code I set up a table of structures, where each structure 
contains:
  The name of the routine
  The signature of the routine
  A pointer to a static function that will call the member function.

During initialization I called a "register_callbacks" function in the Ada 
code with the list of structures.  In the Ada code I set up a function 
pointer to each of the callback routines.  The register_callbacks routine 
sets up a list of pointers to functions based on a match on the function 
name and signature.

I also set up a tagged type on the Ada side to mirror each object instance 
on the C++ side.  The base tagged type contains the "this" pointer for the 
C++ object instance.  A procedure or function for the tagged type 
corresponding to each C++ method, and calls the methods in the C++ code 
using the "this" pointer.

Like I said.  It's not pretty but it works.

BTW: It isn't as ugly as it sounds, but it is certainly not as easy as being 
able to "just use it".

IMHO the gain of using Ada is worth the effort.

Steve
(The Duck)

"Christopher Gosset" <chrg@online.no> wrote in message 
news:mailman.108.1115327462.24457.comp.lang.ada@ada-france.org...
I need to use some  classes from a DLL in my Ada app. I was hoping that
this was a straigthforward thing to do using pragma import and pragma
cpp_class and cpp_constructor. Is there a working example of this
somwhere. I am building the damn dll myself and I am also buliding the
damn .def file myself but the damn thing will still not work. Functions
that are not class members are no problem this works perfect! Are there
any tutorials, sample code available on this? As I see it this is far
from intuitive and its a major reason for NOT converting to ada. What I
would like is a simple "MS Visual Studio " like library brows tree
thing. So instead of having to "build a new operating system" to solve
even the most trivial task, such as calling a member function or a
constructor I could actually add a with clause or import clause and then
be able to see whats available in the lib.

So if anyone has a working sample on the usage of these pragmas  I would
be more than happy.

I assume that the fact that there are no examples of the usage of these
Pragmas in the userguide or reference manual suggests that this is not
as straigth forward as advertised.
/CG





^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Importing and using a C++  class in Ada. Pragma Cpp_Constructor, Cpp_Class
  2005-05-05 21:10 ` Importing and using a C++ class in Ada. Pragma Cpp_Constructor, Cpp_Class Christopher Gosset
  2005-05-06  3:20   ` Importing and using a C++ class in Ada. Pragma Cpp_Constructor,Cpp_Class Steve
@ 2005-05-06  8:07   ` Adrien Plisson
  2005-05-06  9:03   ` Importing and using a C++ class in Ada. Pragma Cpp_Constructor,Cpp_Class Rob W. Norris
  2005-11-09  3:38   ` Importing and using a C++ class in Ada. Pragma Cpp_Constructor, Cpp_Class Anonymous Coward
  3 siblings, 0 replies; 5+ messages in thread
From: Adrien Plisson @ 2005-05-06  8:07 UTC (permalink / raw)


Christopher Gosset wrote:
 > As I see it this is far from intuitive and its a major reason for NOT 
 > converting to ada

try to import a bunch of other languages from C++, and it becomes a 
major reason for NOT converting to C++...

> I assume that the fact that there are no examples of the usage of these
> Pragmas in the userguide or reference manual suggests that this is not
> as straigth forward as advertised.  

are you searching the right reference manual ? those pragmas seems GNAT 
specific, and are described in the GNAT RM (for 3.15p, in 10.2: 
Interfacing to C++, and 1: Implementation defined pragmas).

-- 
rien




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Importing and using a C++  class in Ada. Pragma Cpp_Constructor,Cpp_Class
  2005-05-05 21:10 ` Importing and using a C++ class in Ada. Pragma Cpp_Constructor, Cpp_Class Christopher Gosset
  2005-05-06  3:20   ` Importing and using a C++ class in Ada. Pragma Cpp_Constructor,Cpp_Class Steve
  2005-05-06  8:07   ` Importing and using a C++ class in Ada. Pragma Cpp_Constructor, Cpp_Class Adrien Plisson
@ 2005-05-06  9:03   ` Rob W. Norris
  2005-11-09  3:38   ` Importing and using a C++ class in Ada. Pragma Cpp_Constructor, Cpp_Class Anonymous Coward
  3 siblings, 0 replies; 5+ messages in thread
From: Rob W. Norris @ 2005-05-06  9:03 UTC (permalink / raw)


"Christopher Gosset" <chrg@online.no> scribbled:

>I need to use some  classes from a DLL in my Ada app. I was hoping that
>this was a straigthforward thing to do using pragma import and pragma
>cpp_class and cpp_constructor. Is there a working example of this
>somwhere. I am building the damn dll myself and I am also buliding the
>damn .def file myself but the damn thing will still not work. Functions
>that are not class members are no problem this works perfect! Are there
>any tutorials, sample code available on this? As I see it this is far
>from intuitive and its a major reason for NOT converting to ada. What I
>would like is a simple "MS Visual Studio " like library brows tree
>thing. So instead of having to "build a new operating system" to solve
>even the most trivial task, such as calling a member function or a
>constructor I could actually add a with clause or import clause and then
>be able to see whats available in the lib. 
>
>So if anyone has a working sample on the usage of these pragmas  I would
>be more than happy.
>
>I assume that the fact that there are no examples of the usage of these
>Pragmas in the userguide or reference manual suggests that this is not
>as straigth forward as advertised.  
>/CG

There's an example off the pragmas working in The Big Online Book of
Linux Ada.

http://www.pegasoft.ca/resources/boblap/19.html#19.5

Obivously, it's geared to Linux.

The hard part is when classes get big with virtual functions all over
the place as you have to resolve the actual function mapping and
symbol table offsets yourself.

The simplest way is often to write a pure C style wrapper around the
C++ calls so the Ada can map to that.
-- 
Rob W. Norris
Top Posters Rule? Begin the revolution.



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Importing and using a C++  class in Ada. Pragma Cpp_Constructor, Cpp_Class
  2005-05-05 21:10 ` Importing and using a C++ class in Ada. Pragma Cpp_Constructor, Cpp_Class Christopher Gosset
                     ` (2 preceding siblings ...)
  2005-05-06  9:03   ` Importing and using a C++ class in Ada. Pragma Cpp_Constructor,Cpp_Class Rob W. Norris
@ 2005-11-09  3:38   ` Anonymous Coward
  3 siblings, 0 replies; 5+ messages in thread
From: Anonymous Coward @ 2005-11-09  3:38 UTC (permalink / raw)


In article <mailman.108.1115327462.24457.comp.lang.ada@ada-france.org>, Christopher Gosset wrote:
>
> I need to use some classes from a DLL in my Ada app. I was hoping
> that this was a straigthforward thing to do using pragma import and
> pragma cpp_class and cpp_constructor. Is there a working example of
> this somwhere. I am building the damn dll myself and I am also
> buliding the damn .def file myself but the damn thing will still not
> work. Functions that are not class members are no problem this works
> perfect! Are there any tutorials, sample code available on this? As
> I see it this is far from intuitive and its a major reason for NOT
> converting to ada. What I would like is a simple "MS Visual Studio "
> like library brows tree thing. So instead of having to "build a new
> operating system" to solve even the most trivial task, such as
> calling a member function or a constructor I could actually add a
> with clause or import clause and then be able to see whats available
> in the lib.
> 
> So if anyone has a working sample on the usage of these pragmas I
> would be more than happy.
> 
> I assume that the fact that there are no examples of the usage of
> these Pragmas in the userguide or reference manual suggests that
> this is not as straigth forward as advertised.  /CG

Were you successful in finding what you needed CG?  I'm not sure how
old your post is.. I interfaced to CPP classes before, and have some
examples.  If you're still interested, I might post them.



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2005-11-09  3:38 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20050505100047.AB84F4C40D0@lovelace.ada-france.org>
2005-05-05 21:10 ` Importing and using a C++ class in Ada. Pragma Cpp_Constructor, Cpp_Class Christopher Gosset
2005-05-06  3:20   ` Importing and using a C++ class in Ada. Pragma Cpp_Constructor,Cpp_Class Steve
2005-05-06  8:07   ` Importing and using a C++ class in Ada. Pragma Cpp_Constructor, Cpp_Class Adrien Plisson
2005-05-06  9:03   ` Importing and using a C++ class in Ada. Pragma Cpp_Constructor,Cpp_Class Rob W. Norris
2005-11-09  3:38   ` Importing and using a C++ class in Ada. Pragma Cpp_Constructor, Cpp_Class Anonymous Coward

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox