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=0.2 required=5.0 tests=BAYES_00,INVALID_MSGID, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,fd037befc4df6bdc X-Google-Attributes: gid103376,public From: Robin Stephe Nora Subject: Re: ObjectAda: LPCSTR -> STRING ? Date: 1998/01/06 Message-ID: <34B24858.9DB@erols.com>#1/1 X-Deja-AN: 313305090 Content-Transfer-Encoding: 7bit References: <884055877.1213464581@dejanews.com> Mime-Version: 1.0 Reply-To: leakstan@erols.com Content-Type: text/plain; charset=us-ascii X-Complaints-To: abuse@erols.com X-Trace: winter.news.erols.com 884099201 12705 207.172.138.60 (6 Jan 1998 15:06:41 GMT) Organization: LeakyStain Newsgroups: comp.lang.ada Date: 1998-01-06T00:00:00+00:00 List-Id: matthew_snyder@hotmail.com wrote: > > 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. > I assume you are using ObjectAda 7.1 for Windows (95 or NT?), with the Win32Ada binding (it is helpful if you give these details). If you chase thru all the subtype definitions, you will find that LPCSTR is actually System.Address; it is the address of the first character in the string. It is used to pass strings to/from Win32 API calls. The simplest way to use it is to take the address of the first character of the Ada string. Here is the code I use to erase an entry in a profile (.ini) file: function Win32_WritePrivateProfileStringA (LpSection : in System.Address; lpKeyName : in System.Address; lpString : in System.Address; lpFileName : in System.Address) return Interfaces.C.Int; pragma Import (StdCall, Win32_WritePrivateProfileStringA, "WritePrivateProfileStringA"); procedure Erase (File : in String; Section : In String) is -- null lpKeyName deletes Section in File. Status : Interfaces.C.Int; C_File : constant String := File & Character'First; C_Section : constant String := Section & Character'First; begin Status := Win32_WritePrivateProfileStringA (LpSection => C_Section (C_Section'First)'address, LpKeyName => System.Null_Address, LpString => C_Section (C_Section'First)'Address, LpFileName => C_File (C_File'First)'Address); Check_Status (Status); end Erase; Check_Status raises an exception for an error status. You can also use the facilities in Interfaces.C.String, but since the win32ada bindings do not use those types directly, this always involves unchecked conversion. I find the use of 'address cleaner. -- Stephe