From: "Gerd" <GerdM.O@t-online.de>
Subject: Re: PSTR to Ada String.
Date: 26 Oct 2006 00:56:14 -0700
Date: 2006-10-26T00:56:14-07:00 [thread overview]
Message-ID: <1161849374.326516.254100@b28g2000cwb.googlegroups.com> (raw)
In-Reply-To: <1161809413.511008.220720@h48g2000cwc.googlegroups.com>
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.
next prev parent reply other threads:[~2006-10-26 7:56 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-10-25 20:50 PSTR to Ada String Jade
2006-10-26 7:56 ` Gerd [this message]
2006-10-26 8:13 ` Philippe Bertin
2006-10-26 21:22 ` tmoran
2006-10-26 9:18 ` jca.miranda
2006-10-30 13:22 ` Jade
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox