From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,f58edf3a3fc00db X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2000-12-20 19:25:45 PST Path: supernews.google.com!sn-xit-02!supernews.com!newsfeed.mesh.ad.jp!newshub2.rdc1.sfba.home.com!news.home.com!news1.sttls1.wa.home.com.POSTED!not-for-mail Reply-To: "DuckE" From: "DuckE" Newsgroups: comp.lang.ada References: <91ondg$lpu$1@nnrp1.deja.com> Subject: Re: Interface to C; Storage_Error X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4522.1200 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200 Message-ID: Date: Thu, 21 Dec 2000 03:25:41 GMT NNTP-Posting-Host: 24.6.221.63 X-Complaints-To: abuse@home.net X-Trace: news1.sttls1.wa.home.com 977369141 24.6.221.63 (Wed, 20 Dec 2000 19:25:41 PST) NNTP-Posting-Date: Wed, 20 Dec 2000 19:25:41 PST Organization: Excite@Home - The Leader in Broadband http://home.com/faster Xref: supernews.google.com comp.lang.ada:3305 Date: 2000-12-21T03:25:41+00:00 List-Id: Here's my semi-educated "guess" at the interface to this function: package C renames Interfaces.C; subtype Srv_Handle is C.Unsigned_Long; -- Assumes type for "Handle" is Unsigned_Long type Ctx_Handle is access all C.Unsigned_Long; -- Assumes type for "Ctx_Handle" is Unsigned_Long subtype Flt_Handle is C.C_Float; -- Assumes type for "Flt_Handle" function GetNextVal( srv : access Srv_Handle; rslt : access Srv_Handle; ctx : access Ctx_Handle; name : C.Char_Array; dbl : access C.Double; flt : access Flt_Handle ) return C.Int; pragma Import( C, GetNextVal ); Since the "C" prototype is using "char *" I suspect you need to allocate the data to send to the function. I suspect a call would look something like: -- (untested) srv : aliased Srv_Handle; rslt : aliased Srv_Handle; ctx : aliased Ctx_Handle; name : C.Char_Array := C.To_C( "Name" ); dbl : aliased C.Double; flt : aliased Flt_Handle; result : C.Int; begin result := GetNextVal( srv => srv'access, rslt => rslt'access, ctx => ctx'access, name => name, dbl => dbl'access, flt => flt'access ); In my experience there is often more than one choice of how to interface to C code. I usually stay away from System.Addres, although it is certainly valid to use, I prefer to avoid it. BTW: It was a challenge to interface to the RSLinx 'C' SDK, but I eventually made my way through it. Also... beware of callbacks. I'm not sure if GNAT behaves the same, but with ObjectAda if you are inside of a callback from a "C" library and you attempt to perform an Ada tasking operation (ie: Rendevous or Protected Operation) bad things happen. Apparently the Ada run time library (RTL) keeps additional task control block (TCB) information for Ada tasks. In these cases I have resorted to using OS primatives for implmented my own rendevous. I hope this helps, SteveD "Chris" wrote in message news:91ondg$lpu$1@nnrp1.deja.com... > Hi, all... after a long hiatus in the C++ world, I'm finally getting a > chance to do some more Ada work, at my own suggestion. The ability to > write production-quality multithread code an order of magnitude faster > in Ada might have something to do with it. > > Anyway, I'm having an irritating problem interfacing with a vendor C > library. The relevant stuff: > > typedef void* SRV_HANDLE; > typedef void* CTX_HANDLE; > typedef void* RSLT_HANDLE; > typedef void* FLT_HANDLE; > > int GetNextVal(SRV_HANDLE srv, RSLT_HANDLE rslt, CTX_HANDLE *ctx, > char* name, double* dbl, FLT_HANDLE flt); > > My take on it in Ada (GNAT 3.13p) is: > > type Srv_Handle is new System.Address; > -- same for the other handles > > procedure GetNextVal(Ret : out int; > Srv : Srv_Handle; > Rslt : Rslt_Handle; > Ctx : access Ctx_Handle; > Name : out chars_ptr; > Dbl : access double; > Flt : Flt_Handle); > pragma Import(C, GetNextVal); > pragma Import_Valued_Procedure(GetNextVal); > > Both Name and Dbl are supposedly set/alloc'd by the library. When I > call this, it raises Storage_Error on the library call. I am totally > stumped as to what to fix, or even where to look. Is my Ada declaration > even remotely correct? > Other suggestions? > > > Many thanks. > > --chris > > > Sent via Deja.com > http://www.deja.com/