From: "Deepak Haste" <deepak@teamqsi.com>
Subject: Interface with C
Date: 1999/05/20
Date: 1999-05-20T00:00:00+00:00 [thread overview]
Message-ID: <7i1n9t$6fs@beast.connix.com> (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.
next reply other threads:[~1999-05-20 0:00 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
1999-05-20 0:00 Deepak Haste [this message]
1999-05-20 0:00 ` Maybe this can shed some light( Re: Interface with C Weston T. Pan
1999-05-22 0:00 ` Robert Dewar
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox