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,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,6b4015030847e90a X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!postnews.google.com!b28g2000cwb.googlegroups.com!not-for-mail From: "Gerd" Newsgroups: comp.lang.ada Subject: Re: PSTR to Ada String. Date: 26 Oct 2006 00:56:14 -0700 Organization: http://groups.google.com Message-ID: <1161849374.326516.254100@b28g2000cwb.googlegroups.com> References: <1161809413.511008.220720@h48g2000cwc.googlegroups.com> NNTP-Posting-Host: 62.159.113.204 Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Trace: posting.google.com 1161849380 19088 127.0.0.1 (26 Oct 2006 07:56:20 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 26 Oct 2006 07:56:20 +0000 (UTC) In-Reply-To: <1161809413.511008.220720@h48g2000cwc.googlegroups.com> User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322),gzip(gfe),gzip(gfe) Complaints-To: groups-abuse@google.com Injection-Info: b28g2000cwb.googlegroups.com; posting-host=62.159.113.204; posting-account=_FaVAg0AAAAYUPoPAQYNRFF35JBHf9i7 Xref: g2news2.google.com comp.lang.ada:7206 Date: 2006-10-26T00:56:14-07:00 List-Id: Here an example how it can be done: function AddrToPSTR is new Unchecked_Conversion(System.Address, Win32.PSTR); procedure GetHostName (Name : out STRING; Len : out Integer; RC : out INTEGER) is Erg : Win32.INT; HostName : STRING (1..255); begin -- The result (excluding the \0) must fit into "Name" Erg := gethostname (AddrToPSTR (HostName'ADDRESS), Name'LENGTH + 1); if Erg = SOCKET_ERROR then RC := INTEGER(WSAGetLastError); else RC := NO_ERROR; Name := (others => ' '); -- Should work correct, as "gethostname" should never return more characters -- than "Name" can get. for i in HostName'FIRST .. HostName'LAST loop if HostName (i) = ASCII.NUL then Len := i - 1; return; else Name (Name'FIRST + i - 1) := HostName (i); end if; end loop; end if; end GetHostName; Jade schrieb: > Hi > I am using GNAT's ada bindings and with functions like gethostname, etc > they choose to have a return value as a WIN32.PSTR. > However, all my ada functions require either ada standard strings or > characters. I was wondering if there is way of converting PSTR to an > ada string. > > Thanks, > > Jade.