comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Interfacing with C
Date: Mon, 18 May 2009 13:58:35 +0200
Date: 2009-05-18T13:58:36+02:00	[thread overview]
Message-ID: <6i3cwvzndx7y.1j38k2uakyqyp$.dlg@40tude.net> (raw)
In-Reply-To: 250d9b93-13bf-4375-8b35-a1b0a7f74d99@j12g2000vbl.googlegroups.com

On Mon, 18 May 2009 04:29:44 -0700 (PDT), cedric wrote:

> I would like to connect a C interface to another software package with
> my Ada programs.
> 
> The h-file of the api contains the following pre-processor commands:
> 
> #ifdef SPSSXD_EXPORTS
> # define SPSSXD_API __declspec(dllexport)
> #else
> # if MS_WINDOWS
> #   define SPSSXD_API __declspec(dllimport)
> # else
> #   define SPSSXD_API
> # endif
> #endif

From this you should figure out the call convention. It can be either C or
stdcall. The rest can be usually ignored. Usually this stuff tells whether
the entry point is a reference or else a vector for dynamic run-time
linking or else an entry point, when the library itself is compiled,
nothing interesting for an Ada client.

> Some functions headers are
> 
> SPSSXD_API bool IsBackendReady();
> SPSSXD_API int SetUpFromSPSS(SpssAdapter* anAdapter, SpssXDSmb*
> anSmb);
> 
> What do I have to do to get a connection between the C functions and
> my Ada program with regard to the commands of the pre-processor?

Print the preprocessor output if you are in doubts. Otherwise it could be
like this:

   with Interfaces.C;  use Interfaces.C;
   ...
   function IsBackendReady return Int; -- C does not have Boolean
   pragma Import (stdcall, IsBackendReady, "IsBackendReady");

   type SpssAdapter is record
       ... -- Components of struct SpssAdapter
   end record;
   pragma Convention (C, SpssAdapter);

   type anSmb is record
       ... -- Components of struct anSmb
   end record;
   pragma Convention (C, anSmb);

   function SetUpFromSPSS
      (  anAdapter : access SpssAdapter;
          anSmb : access SpssXDSmb
      );
   pragma Import (stdcall, SetUpFromSPSS, "SetUpFromSPSS");

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



  parent reply	other threads:[~2009-05-18 11:58 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-05-18 11:29 Interfacing with C cedric
2009-05-18 11:51 ` Maciej Sobczak
2009-05-18 11:58 ` Dmitry A. Kazakov [this message]
2009-05-18 12:11   ` Ludovic Brenta
2009-05-18 12:13     ` Ludovic Brenta
2009-06-01  8:24   ` David Thompson
     [not found] <vhiln6cllz7.fsf@grotte.ifi.uio.no>
1999-12-30  0:00 ` Simon Wright
1999-12-31  0:00 ` Jerry van Dijk
1999-12-31  0:00   ` Simon Wright
     [not found] <7rtlav$bm7$1@nnrp1.deja.com>
     [not found] ` <37e2b0e7.0@news.pacifier.com>
1999-09-22  0:00   ` Richard D Riehle
1999-09-22  0:00     ` Ted Dennison
1999-09-22  0:00       ` David Botton
1999-09-23  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