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=-2.9 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI autolearn=unavailable autolearn_force=no version=3.4.4 X-Google-Thread: 103376,97d5e85b59d5e24c X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!news.glorb.com!fr.ip.ndsoftware.net!proxad.net!freenix!enst.fr!melchior!cuivre.fr.eu.org!melchior.frmug.org!not-for-mail From: Stephen Leake Newsgroups: comp.lang.ada Subject: Re: Ada equivalent to С++ header sentence. Date: 20 Aug 2004 08:37:26 -0400 Organization: Cuivre, Argent, Or Message-ID: References: <3f27506b.0408200022.76094a5e@posting.google.com> NNTP-Posting-Host: lovelace.ada-france.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: melchior.cuivre.fr.eu.org 1093005465 64027 212.85.156.195 (20 Aug 2004 12:37:45 GMT) X-Complaints-To: usenet@melchior.cuivre.fr.eu.org NNTP-Posting-Date: Fri, 20 Aug 2004 12:37:45 +0000 (UTC) To: comp.lang.ada@ada-france.org Return-Path: In-Reply-To: <3f27506b.0408200022.76094a5e@posting.google.com> User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3 X-Virus-Scanned: by amavisd-new-20030616-p7 (Debian) at ada-france.org X-BeenThere: comp.lang.ada@ada-france.org X-Mailman-Version: 2.1.4 Precedence: list List-Id: "Gateway to the comp.lang.ada Usenet newsgroup" List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Xref: g2news1.google.com comp.lang.ada:2889 Date: 2004-08-20T08:37:26-04:00 rhezusfactor@yahoo.com (Johnswort) writes: > I try to make a binding on an API, which has a header in C++ syntax. > As a complete moron in both C/C++, I want to grab the last straw > before giving up. So I ask for a hint: what would be the Ada > equivalent to the following: > > typedef BOOL (_stdcall T_hcConnect)(LPSTR lszCmd); This declares T_hcConnect to be a type designating a function that takes an LPSTR parameter and returns a BOOL result. The normal use in C for such a type is to designate a pointer to a function. So the equivalent in Ada is a function access type: type T_hcConnect is access function (lszCmd : in LPSTR) return BOOL; > Presumingly, LPSTR may come from Win32. Yes, it stands for "Long Pointer to String". You might be tempted to define it in Ada as: type LPSTR is access String; -- WRONG! But since an Ada string is an Ada array, and a C string is just a pointer to Char, this is wrong. You can use Interfaces.C.Pointers, but that gets very cumbersome. Use System.Address, and make sure you append ASCII.Nul to the end of any strings passed to C. > Just in case, VB header translates it into > > Declare Function hbConnect Lib "hapi.dll" Alias "hcConnect" (ByVal > command As String) As Long That's similar. But VB puts wrappers around such functions for you, so it's not completely identical. For instance, it's not a type. Since you appear to be importing a DLL, there are better ways than declaring function access types. Read the GNAT user guide section on importing DLLs. Or, as someone else pointed out, try using GNATCOM. -- -- Stephe