comp.lang.ada
 help / color / mirror / Atom feed
* combine Ada with MS VS C++
@ 2005-03-16 13:04 ich_bin_elvis
  2005-03-16 14:18 ` Larry Kilgallen
  2005-03-17  3:32 ` David Botton
  0 siblings, 2 replies; 9+ messages in thread
From: ich_bin_elvis @ 2005-03-16 13:04 UTC (permalink / raw)


Hi,

Im working on an project where we have an drone traversing a field on
GPS signals, this project is written in MS VS C++. Our plan is to "pull
out" the most saefty critical code to ada. We have created an DLL file
and imported the adadll.lib file in MS VS C++. We have managed to move
some functions for distance and angle to ada. These functions return
only one "double" but the problem is that the VS C++ code holds a lot
of global variables.Some times our functions need to update more than
one variable. Is there a possibilyty to return more than one variable
from ada to MS VS C++(This is where the main is). We have also tried to
move the global variables we need to Ada and use get and set methods to
acsess them in c++. Is there a possibliity to do this and if some one
got articles paper on the subject i would appriciate a copy. Help ideas
on the problem is appriciated


Regards
PS send articles to : ronny@the-wildbunch.net




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

* Re: combine Ada with MS VS C++
  2005-03-16 13:04 combine Ada with MS VS C++ ich_bin_elvis
@ 2005-03-16 14:18 ` Larry Kilgallen
  2005-03-16 14:53   ` ich_bin_elvis
  2005-03-17  3:32 ` David Botton
  1 sibling, 1 reply; 9+ messages in thread
From: Larry Kilgallen @ 2005-03-16 14:18 UTC (permalink / raw)


In article <1110978291.469762.247330@g14g2000cwa.googlegroups.com>, ich_bin_elvis@hotmail.com writes:

> Im working on an project where we have an drone traversing a field on
> GPS signals, this project is written in MS VS C++. Our plan is to "pull
> out" the most saefty critical code to ada. We have created an DLL file
> and imported the adadll.lib file in MS VS C++. We have managed to move
> some functions for distance and angle to ada. These functions return
> only one "double" but the problem is that the VS C++ code holds a lot
> of global variables.Some times our functions need to update more than
> one variable. Is there a possibilyty to return more than one variable
> from ada to MS VS C++(This is where the main is).

The typical approach to this with Ada is to create not a function
but a procedure.  A procedure can have multiple output parameters,
one of which could be the new value for the global.

The only real disadvantage this has over a function is that functions
can return arrays of undetermined (prior to the call) size, but that does
not seem to be your situation (and would be hard to receive in C++ anyway.



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

* Re: combine Ada with MS VS C++
  2005-03-16 14:18 ` Larry Kilgallen
@ 2005-03-16 14:53   ` ich_bin_elvis
  2005-03-16 16:42     ` Martin Krischik
  2005-03-16 21:44     ` Ludovic Brenta
  0 siblings, 2 replies; 9+ messages in thread
From: ich_bin_elvis @ 2005-03-16 14:53 UTC (permalink / raw)


Thanks,How would you declared this in ada an MS VS C++ for a procedure
the procedures is as follows in Ada. Vr and Vl are two global double
variablers in the C++ program.

Ada:

procedure CheckBuffer(vr,vl : in out is Interfaces.C.double);

Do I need to write something special in the *.DEF file?? except from
EXPORTS CheckBuffer




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

* Re: combine Ada with MS VS C++
  2005-03-16 14:53   ` ich_bin_elvis
@ 2005-03-16 16:42     ` Martin Krischik
  2005-04-12 10:18       ` ich_bin_elvis
  2005-03-16 21:44     ` Ludovic Brenta
  1 sibling, 1 reply; 9+ messages in thread
From: Martin Krischik @ 2005-03-16 16:42 UTC (permalink / raw)


ich_bin_elvis@hotmail.com wrote:

> Thanks,How would you declared this in ada an MS VS C++ for a procedure
> the procedures is as follows in Ada. Vr and Vl are two global double
> variablers in the C++ program.
> 
> Ada:
> 
> procedure CheckBuffer(vr,vl : in out is Interfaces.C.double);
> 
> Do I need to write something special in the *.DEF file?? except from
> EXPORTS CheckBuffer

Depending an calling convention and/or pragma Export you might need

EXPORTS CheckBuffer@8

or

EXPORTS _CheckBuffer CheckBuffer

C/C++ are a bit tricky in that respect

Martin
-- 
mailto://krischik@users.sourceforge.net
Ada programming at: http://ada.krischik.com




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

* Re: combine Ada with MS VS C++
  2005-03-16 14:53   ` ich_bin_elvis
  2005-03-16 16:42     ` Martin Krischik
@ 2005-03-16 21:44     ` Ludovic Brenta
  2005-03-16 22:18       ` Randy Brukardt
  1 sibling, 1 reply; 9+ messages in thread
From: Ludovic Brenta @ 2005-03-16 21:44 UTC (permalink / raw)


 writes:
> Thanks,How would you declared this in ada an MS VS C++ for a procedure
> the procedures is as follows in Ada. Vr and Vl are two global double
> variablers in the C++ program.
>
> Ada:
>
> procedure CheckBuffer(vr,vl : in out is Interfaces.C.double);
>
> Do I need to write something special in the *.DEF file?? except from
> EXPORTS CheckBuffer

I don't program on Windows, so I can't help you with the exporting
from Ada.  You may need to use all three arguments to pragma Export in
order to get the link name right; this is the platform-dependent part.
So you'd say something like:

procedure Check_Buffer (vr, vl : in out Interfaces.C.double);
pragma Export (Convention => C, Entity => Check_Buffer,
               External_Name => "CheckBuffer", -- this is...
               Link_Name => "something");      -- ...the hard part

Once you've done this, you would import this procedure into C++ as
follows:

extern "C" void CheckBuffer (double* vr, double* vl);

The "C" is necessary to avoid C++ name mangling by the linker.

Per Ada Reference Manual, B.3(68):

      68. (...) an Ada out or in out parameter
          of an elementary type T, is passed as a t* argument to a C
          function, where t is the C type corresponding to the Ada type
          T. In the case of an elementary out or in out parameter, a
          pointer to a temporary copy is used to preserve by-copy
          semantics.

-- 
Ludovic Brenta.



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

* Re: combine Ada with MS VS C++
  2005-03-16 21:44     ` Ludovic Brenta
@ 2005-03-16 22:18       ` Randy Brukardt
  0 siblings, 0 replies; 9+ messages in thread
From: Randy Brukardt @ 2005-03-16 22:18 UTC (permalink / raw)


"Ludovic Brenta" <ludovic.brenta@insalien.org> wrote in message
news:87hdjb5kqd.fsf@insalien.org...
> writes:
...
> I don't program on Windows, so I can't help you with the exporting
> from Ada.  You may need to use all three arguments to pragma Export in
> order to get the link name right; this is the platform-dependent part.
> So you'd say something like:
>
> procedure Check_Buffer (vr, vl : in out Interfaces.C.double);
> pragma Export (Convention => C, Entity => Check_Buffer,
>                External_Name => "CheckBuffer", -- this is...
>                Link_Name => "something");      -- ...the hard part

I'd leave out the link name part. The intent is that you specify *either*
the link name *or* the external name. The external name is the name as it
appears in C. I think all Windows Ada compilers can generate the link name
from that name; certainly we only used the External_Name in Claw to link to
Win32.

This only works if you turn off name-mangling as suggested in the previous
response. You could use the link name instead to manually provide the
mangled name, but that seems like a lot of work for little gain.

                  Randy.







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

* Re: combine Ada with MS VS C++
  2005-03-16 13:04 combine Ada with MS VS C++ ich_bin_elvis
  2005-03-16 14:18 ` Larry Kilgallen
@ 2005-03-17  3:32 ` David Botton
  1 sibling, 0 replies; 9+ messages in thread
From: David Botton @ 2005-03-17  3:32 UTC (permalink / raw)


I would recommend creating an Ada COM object using GNATCOM

http://www.gnavi.org/gnatcom

The advantage is that not only will you gain the features you are 
looking for, but long term you have access to the object via .NET as 
well.

David Botton




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

* Re: combine Ada with MS VS C++
  2005-03-16 16:42     ` Martin Krischik
@ 2005-04-12 10:18       ` ich_bin_elvis
  2005-04-12 14:38         ` ich_bin_elvis
  0 siblings, 1 reply; 9+ messages in thread
From: ich_bin_elvis @ 2005-04-12 10:18 UTC (permalink / raw)


Got the Checkbuffer function working. But when I add  functions for
angle(x1,y1,x2,y2) and distance(x1,y1,x2,y2). in ada that returns one
double My program behaves strange. I get no errors but the program
crashes somtimes when I click a button twice. why do I have to write
checkbuffer@8 ? this is not an ordinal is it? do anyone have any
articels on this subject? Or for ada usage in windows/visual studio?




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

* Re: combine Ada with MS VS C++
  2005-04-12 10:18       ` ich_bin_elvis
@ 2005-04-12 14:38         ` ich_bin_elvis
  0 siblings, 0 replies; 9+ messages in thread
From: ich_bin_elvis @ 2005-04-12 14:38 UTC (permalink / raw)


Hi, After some testing we found out that the problem was that in our
C++ program we had an struct described below.

typedef struct tagpoint
{
	double   x;
	double   y;
} point;

and Angle is prototyped like

extern "C" double Angle(double x1, double y1, double x2, double y2);

We used it like this:

double vinkel1;
point p0,p1,p2,p3;

and we sendt the parameters to Angle in the form of.

vinkel1 = Angle(p0.x, p0.y, p3.x, p3.y);

we found out that we need to create temorary variabels and send them
instead is this realy neccesary? In Ada we uses Interfaces.C.double to
recive the parameters and return the ange. Any comment on this is
apreciated.

Regards
Ronny




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

end of thread, other threads:[~2005-04-12 14:38 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-03-16 13:04 combine Ada with MS VS C++ ich_bin_elvis
2005-03-16 14:18 ` Larry Kilgallen
2005-03-16 14:53   ` ich_bin_elvis
2005-03-16 16:42     ` Martin Krischik
2005-04-12 10:18       ` ich_bin_elvis
2005-04-12 14:38         ` ich_bin_elvis
2005-03-16 21:44     ` Ludovic Brenta
2005-03-16 22:18       ` Randy Brukardt
2005-03-17  3:32 ` David Botton

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