From: matthew_snyder@hotmail.com
Subject: RE: ObjectAda: LPCSTR -> STRING ?
Date: 1998/01/20
Date: 1998-01-20T00:00:00+00:00 [thread overview]
Message-ID: <885329887.836370436@dejanews.com> (raw)
OK. Here's what I ended up doing. Please let me know if there's an
easier way.
type CHARACTER_POINTER is access CHARACTER;
function TO_CHARACTER_POINTER is new ADA.UNCHECKED_CONVERSION(
WIN32.LPCSTR, CHARACTER_POINTER ); function TO_UNSIGNED_32 is new
ADA.UNCHECKED_CONVERSION( WIN32.LPCSTR, UNSIGNED_32 ); function
TO_LPCSTR is new ADA.UNCHECKED_CONVERSION( UNSIGNED_32, WIN32.LPCSTR );
procedure TO_ADA_STRING( STRING_PTR : in WIN32.LPCSTR;
NEW_STRING : in out STRING;
LAST : in out INTEGER ) is
TEMP_STRING_PTR : WIN32.LPCSTR := STRING_PTR;
ADA_STRING : STRING( 1 .. 80 );
TEMP_32 : UNSIGNED_32;
CHAR_PTR : CHARACTER_POINTER;
begin
-- Get the length of the string
LAST := INTEGER( WIN32.WINBASE.LSTRLEN( STRING_PTR ) );
-- Loop through and copy "C" string to Ada string
for STRING_INDEX in 1 .. LAST loop
-- Convert the string pointer to a character pointer
CHAR_PTR := TO_CHARACTER_POINTER( TEMP_STRING_PTR );
-- Add the character to the ada string
ADA_STRING( STRING_INDEX ) := CHAR_PTR.all;
-- Convert the string pointer to an unsigned 32
TEMP_32 := TO_UNSIGNED_32( TEMP_STRING_PTR );
-- Increment the unsigned 32
TEMP_32 := TEMP_32 + 1;
-- Convert the unsigned 32 back to a string pointer
TEMP_STRING_PTR := TO_LPCSTR( TEMP_32 );
end loop;
NEW_STRING( 1 .. NEW_STRING'LAST ) := ADA_STRING( 1 .. NEW_STRING'LAST
);
end TO_ADA_STRING;
-------------------==== Posted via Deja News ====-----------------------
http://www.dejanews.com/ Search, Read, Post to Usenet
next reply other threads:[~1998-01-20 0:00 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
1998-01-20 0:00 matthew_snyder [this message]
1998-01-21 0:00 ` ObjectAda: LPCSTR -> STRING ? Pascal Obry
-- strict thread matches above, loose matches on Subject: below --
1998-01-05 0:00 matthew_snyder
1998-01-06 0:00 ` Martin C. Carlisle
1998-01-11 0:00 ` Jerry van Dijk
1998-01-12 0:00 ` Pascal Obry
1998-01-06 0:00 ` Robin Stephe Nora
1998-01-06 0:00 ` Robert Dewar
1998-01-07 0:00 ` Stephen Leake
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox