comp.lang.ada
 help / color / mirror / Atom feed
* problem with CPP_* pragmas
@ 2004-03-10 22:31 Szymon Guz
  2004-03-11 13:18 ` Georg Bauhaus
  0 siblings, 1 reply; 6+ messages in thread
From: Szymon Guz @ 2004-03-10 22:31 UTC (permalink / raw)


Hi,
I keep on trying to create an Ada binding to a C++ dll library. Now I 
try to solve a small problem with the CPP_* pragmas so I wrote some 
small dll library in C++ and try to make the Ada binding, but I cannot 
do one thing. I wrote sth like this:


********************************************************************
      1. with Win32;
      2. with Interfaces.CPP;
      3.
      4. package TestClass is
      5.
      6.
      7.    type CA is tagged
      8.       record
      9.          VTable : Interfaces.CPP.Vtable_Ptr;
     10.          m1     : Win32.INT;
     11.          d2     : Win32.DOUBLE;
     12.       end record;
     13.    type CA_Ptr is access all CA'Class;
     14.    function Create return CA;
     15.
     16.    pragma CPP_Vtable(
     17.       Entity      => CA,
     18.       VTable_Ptr  => VTable,
     19.       Entry_Count => 5);
     20.    pragma CPP_Class(Entity => CA);
     21.    pragma CPP_Constructor(Create);
     22.

********************************************************************

My problem is that I still get a compiler error like this:
on line 17:
CPP_Class tagged type expected
on line 21:
pragma "Cpp_Constructor" requires function returning a CPP_Class type

Could someone tell me what i wrong here, please ?

Szymon Guz



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

* Re: problem with CPP_* pragmas
  2004-03-10 22:31 problem with CPP_* pragmas Szymon Guz
@ 2004-03-11 13:18 ` Georg Bauhaus
  2004-03-11 21:55   ` Szymon Guz
  0 siblings, 1 reply; 6+ messages in thread
From: Georg Bauhaus @ 2004-03-11 13:18 UTC (permalink / raw)


Szymon Guz <guzo@stud.ics.p.lodz.pl> wrote:
This compiles (not tried on Windows(TM) though):

with Interfaces.CPP;

   package TestClass is


        type CA is tagged
          record
             VTable : Interfaces.CPP.Vtable_Ptr;
           end record;

        pragma CPP_Class(Entity => CA);
        pragma CPP_Vtable(
           Entity      => CA,
           VTable_Ptr  => VTable,
           Entry_Count => 5);

        function Create return CA'Class;
        --probably: pragma Import(CPP, Create, ...);
        pragma CPP_Constructor(Create);

   end TestClass;

One change ist moving Create down so that CA is known to be
a CPP_Class type when Create is declared. "return CA'Class"
is what my GNAT RM says is required.


-- Georg



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

* Re: problem with CPP_* pragmas
  2004-03-11 13:18 ` Georg Bauhaus
@ 2004-03-11 21:55   ` Szymon Guz
  2004-03-12 18:52     ` Georg Bauhaus
  0 siblings, 1 reply; 6+ messages in thread
From: Szymon Guz @ 2004-03-11 21:55 UTC (permalink / raw)


Georg Bauhaus wrote:
> Szymon Guz <guzo@stud.ics.p.lodz.pl> wrote:
> This compiles (not tried on Windows(TM) though):
> 
> One change ist moving Create down so that CA is known to be
> a CPP_Class type when Create is declared. "return CA'Class"
> is what my GNAT RM says is required.
> 
> 
> -- Georg

Thanks, that helped me a lot, but I still have a problem. There is a 
virtual function in C++:


virtual void CA::Met1(int par1, double par2);

I wrote in Ada sth like this:

procedure Met1 (
   this : CA_Ptr;
   par1 : Win32.INT;
   par2 : Win32.DOUBLE );

now I try to import the function from dll to be a virtual function, so I 
wrote:

pragma CPP_Virtual (
    Entity     => Met1,
    VTable_Ptr => VTable,
    Position = 1);

My problem is that I still get the same error:
testclass.ads:36:21: pragma "Cpp_Virtual" must reference a primitive 
operation

What do I do wrong ?



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

* Re: problem with CPP_* pragmas
  2004-03-11 21:55   ` Szymon Guz
@ 2004-03-12 18:52     ` Georg Bauhaus
  2004-03-12 19:22       ` Szymon Guz
  0 siblings, 1 reply; 6+ messages in thread
From: Georg Bauhaus @ 2004-03-12 18:52 UTC (permalink / raw)


Szymon Guz <guzo@stud.ics.p.lodz.pl> wrote:
: 
: virtual void CA::Met1(int par1, double par2);

: procedure Met1 (
:   this : CA_Ptr;
:   par1 : Win32.INT;
:   par2 : Win32.DOUBLE );
 
: My problem is that I still get the same error:
: testclass.ads:36:21: pragma "Cpp_Virtual" must reference a primitive 
: operation
: 
: What do I do wrong ?

my initial guess is that Met1 is a classwide, not a primitive
operation of type CA.

Georg



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

* Re: problem with CPP_* pragmas
  2004-03-12 18:52     ` Georg Bauhaus
@ 2004-03-12 19:22       ` Szymon Guz
  2004-03-12 20:16         ` Georg Bauhaus
  0 siblings, 1 reply; 6+ messages in thread
From: Szymon Guz @ 2004-03-12 19:22 UTC (permalink / raw)


Georg Bauhaus wrote:
> Szymon Guz <guzo@stud.ics.p.lodz.pl> wrote:
> : 
> : virtual void CA::Met1(int par1, double par2);
> 
> : procedure Met1 (
> :   this : CA_Ptr;
> :   par1 : Win32.INT;
> :   par2 : Win32.DOUBLE );
>  
> : My problem is that I still get the same error:
> : testclass.ads:36:21: pragma "Cpp_Virtual" must reference a primitive 
> : operation
> : 
> : What do I do wrong ?
> 
> my initial guess is that Met1 is a classwide, not a primitive
> operation of type CA.
> 
> Georg

well, I think that you're right, but I'd like to use the pragma 
Cpp_Virtual in some similar classes as some of them have more than 40 
functions and I don't need and don't want to rewrite all of that in ada. 
Is there some other way to import the above function into Ada than using 
pragma Import and rewriting all the functions ? I'd like to place the 
function in the virtual table in some way but I don't have any idea how 
to do that.



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

* Re: problem with CPP_* pragmas
  2004-03-12 19:22       ` Szymon Guz
@ 2004-03-12 20:16         ` Georg Bauhaus
  0 siblings, 0 replies; 6+ messages in thread
From: Georg Bauhaus @ 2004-03-12 20:16 UTC (permalink / raw)


Szymon Guz <guzo@stud.ics.p.lodz.pl> wrote:

: Is there some other way to import the above function into Ada than using 
: pragma Import and rewriting all the functions ?

I'm not sure why you say rewrite. If you import the function
it usually means that the body of the function is not written as part of
your program's text, but imported from somewhere else, in a compiled
form. That is you write an Ada spec for the function and you import
its body. In this case it is imported from compiled C++ with the help
of an additional pragma that "links" the function to CA and its vtable,
if I understand this correctly.




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

end of thread, other threads:[~2004-03-12 20:16 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-03-10 22:31 problem with CPP_* pragmas Szymon Guz
2004-03-11 13:18 ` Georg Bauhaus
2004-03-11 21:55   ` Szymon Guz
2004-03-12 18:52     ` Georg Bauhaus
2004-03-12 19:22       ` Szymon Guz
2004-03-12 20:16         ` Georg Bauhaus

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