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.1 required=5.0 tests=BAYES_00,INVALID_MSGID, MSGID_RANDY,PP_MIME_FAKE_ASCII_TEXT autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII X-Google-Thread: 103376,98726e33eaf68ac4 X-Google-Attributes: gid103376,public From: "Pascal Obry" Subject: Re: ObjectAda: LPCSTR -> STRING ? Date: 1998/01/21 Message-ID: <6a4d9r$8h5$1@cf01.edf.fr>#1/1 X-Deja-AN: 317953445 References: <885329887.836370436@dejanews.com> X-MimeOLE: Produced By Microsoft MimeOLE V4.72.2106.4 Organization: EDF - Direction des Etudes et Recherches Newsgroups: comp.lang.ada Date: 1998-01-21T00:00:00+00:00 List-Id: >OK. Here's what I ended up doing. Please let me know if there's an >easier way. > Yes there is ! And it has already been posted (12/01/98) : LP : Win32.LPCSTR; S : String := Interfaces.C.Strings.Value (Win32.To_Chars_Ptr (LP)); Pascal. -- --|------------------------------------------------------------ --| Pascal Obry Team-Ada Member | --| | --| EDF-DER-IPN-SID- Ing�nierie des Syst�mes d'Informations | --| | --| Bureau G1-010 e-mail: pascal.obry@der.edfgdf.fr | --| 1 Av G�n�ral de Gaulle voice : +33-1-47.65.50.91 | --| 92141 Clamart CEDEX fax : +33-1-47.65.50.07 | --| FRANCE | --|------------------------------------------------------------ --| --| http://ourworld.compuserve.com/homepages/pascal_obry --| --| "The best way to travel is by means of imagination" matthew_snyder@hotmail.com a �crit dans le message <885329887.836370436@dejanews.com>... > 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