comp.lang.ada
 help / color / mirror / Atom feed
* ObjectAda: LPCSTR -> STRING ?
@ 1998-01-05  0:00 matthew_snyder
  1998-01-06  0:00 ` Martin C. Carlisle
  1998-01-06  0:00 ` Robin Stephe Nora
  0 siblings, 2 replies; 9+ messages in thread
From: matthew_snyder @ 1998-01-05  0:00 UTC (permalink / raw)



I'm working with Aonix ObjectAda 7.1 and I need to figure
out a way to convert a LPCSTR to an Ada STRING.  I'd appreciate
any help.  Thanks.

-------------------==== Posted via Deja News ====-----------------------
      http://www.dejanews.com/     Search, Read, Post to Usenet




^ permalink raw reply	[flat|nested] 9+ messages in thread
* RE: ObjectAda: LPCSTR -> STRING ?
@ 1998-01-20  0:00 matthew_snyder
  1998-01-21  0:00 ` Pascal Obry
  0 siblings, 1 reply; 9+ messages in thread
From: matthew_snyder @ 1998-01-20  0:00 UTC (permalink / 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




^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~1998-01-21  0:00 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-01-05  0:00 ObjectAda: LPCSTR -> STRING ? 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
  -- strict thread matches above, loose matches on Subject: below --
1998-01-20  0:00 matthew_snyder
1998-01-21  0:00 ` Pascal Obry

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox