comp.lang.ada
 help / color / mirror / Atom feed
* Interface with C
@ 1999-05-20  0:00 Deepak Haste
  1999-05-20  0:00 ` Maybe this can shed some light( " Weston T. Pan
  0 siblings, 1 reply; 3+ messages in thread
From: Deepak Haste @ 1999-05-20  0:00 UTC (permalink / raw)


Hello,

I am implementing an ADA routine that interfaces with a Win32 C-library on
an NT. I am trying to import an array into an ADA procedure from a
C -function call.

The C function looks like this

 > DllImport int GetKnownBadComponents_RT(int **bad_components,  ...);

A call to this function would give us the address of the array.

****************************************************************************
***
The corresponding ADA binding looks like this :

 >  type components is array(Integer range <>) of Integer;

------------------------------------------------
>   pragma convention(C,components);
------------------------------------------------

 >  type components_ptr is access components;

 >  function GetKnownBadComponents_RT(bad_components_ptr : in
components_ptr; ..) return Integer;
                                                                           -
- function prototype

****************************************************************************
*
While calling this function from an ada procedure I do:

 >     badcomponents_ptr : components_ptr := new components(0 .. 9);
                                                                           -
- initialized to point to a 10 component array

 >     ret_code := GetKnownBadComponents_RT(badcomponents_ptr,...);
                                                                           -
- the actual function call

 >     for Item in badcomponents_ptr.all'range loop
 >           Put(Integer'Image(badcomponents_ptr.all(Item)));
 >     end loop;
                                                                           -
- display array elements

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

Now, I know that the C function does not pass array of size greater than 5.
Also, the inclusion/exclusion of the pragma convention makes it behave
differently. When pragma is excluded, the procedure gives constraint error
at the function call. When included, I get the first element correctly.
However the display loop goes infinite giving out the rest as garbage. Any
suggestions will be greatly appreciated.

Thanks,
Deepak Haste.






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

end of thread, other threads:[~1999-05-22  0:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-05-20  0:00 Interface with C Deepak Haste
1999-05-20  0:00 ` Maybe this can shed some light( " Weston T. Pan
1999-05-22  0:00   ` Robert Dewar

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