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=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,7117a84edbedc116 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-04-15 21:25:08 PST Path: archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-09!supernews.com!pd2nf1so.cg.shawcable.net!residential.shaw.ca!chi1.webusenet.com!news.webusenet.com!cyclone1.gnilink.net!wn14feed!worldnet.att.net!204.127.198.203!attbi_feed3!attbi.com!rwcrnsc53.POSTED!not-for-mail From: "Steve" Newsgroups: comp.lang.ada References: <3e9b28f8$1_4@newsfeed> Subject: Re: Interfacing Ada with C X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1106 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 Message-ID: NNTP-Posting-Host: 12.211.13.75 X-Complaints-To: abuse@attbi.com X-Trace: rwcrnsc53 1050467107 12.211.13.75 (Wed, 16 Apr 2003 04:25:07 GMT) NNTP-Posting-Date: Wed, 16 Apr 2003 04:25:07 GMT Organization: AT&T Broadband Date: Wed, 16 Apr 2003 04:25:07 GMT Xref: archiver1.google.com comp.lang.ada:36178 Date: 2003-04-16T04:25:07+00:00 List-Id: "Steve" wrote in message news:pD3na.499811$sf5.816502@rwcrnsc52.ops.asp.att.net... > A different way of doing this: > > In Ada you should be able to use Interfaces.C.Pointers and then declare your > procedure as follows: > > package Interface_Wide_String is > new Interfaces.C.Pointers( Interfaces.C.size_T, > Interfaces.C.WChar_T, > Interfaces.C.WChar_Array, > Interfaces.C.Wide_Nul ); [snip] > > I haven't tested this, but I think it will work (it compiles anyway). > > Steve > (The Duck) > I created a small set of sources and tested my example (it does work). Here's the source for my test case: ------ File: clatest.c ------ #include extern void One( wchar_t *text ); extern void adainit(); extern void adafinal(); int main(int argc, char* argv[]) { adainit(); One( L"Hello from Ada" ); adafinal(); return 0; } ------ File: One_Package.ads ------ with Interfaces.C; with Interfaces.C.Pointers; package One_Package is package Interface_Wide_String is new Interfaces.C.Pointers( Interfaces.C.size_T, Interfaces.C.WChar_T, Interfaces.C.WChar_Array, Interfaces.C.Wide_Nul ); procedure One( Name : in Interface_Wide_String.Pointer ); pragma Export( C, One, "One" ); end One_Package; ------ File: One_Package.adb ------ with Ada.Wide_Text_Io; package body One_Package is procedure One( Name : in Interface_Wide_String.Pointer ) is begin Ada.Wide_Text_Io.Put_Line( Interfaces.C.To_Ada( Interface_Wide_String.Value( Name ) ) ); end One; end One_Package; Steve (The Duck)