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=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,47957cb8c33729e5 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Newsgroups: comp.lang.ada Subject: Re: Thick Ada bindings to C Win32 References: <2vjnfbF2lioiaU1@uni-berlin.de> <1Ucld.25101$KJ6.2286@newsread1.news.pas.earthlink.net> From: Brian May Date: Mon, 29 Nov 2004 10:45:09 +1100 Message-ID: User-Agent: Gnus/5.1007 (Gnus v5.10.7) Emacs/21.3 (gnu/linux) Cancel-Lock: sha1:eWmV6+/cOZVxrOpMhFg4HmaXCHE= MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii NNTP-Posting-Host: snoopy.microcomaustralia.com.au X-Trace: news.melbourne.pipenetworks.com 1101685488 202.173.153.89 (29 Nov 2004 09:44:48 +1000) X-Complaints-To: abuse@pipenetworks.com X-Abuse-Info: Please forward all headers to enable your complaint to be properly processed. Path: g2news1.google.com!news4.google.com!news.glorb.com!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!news-north.connect.com.au!news.alphalink.com.au!news.melbourne.pipenetworks.com!not-for-mail Xref: g2news1.google.com comp.lang.ada:6604 Date: 2004-11-29T10:45:09+11:00 List-Id: >>>>> "Brian" == Brian May writes: Brian> I seem to remember that I encountered problems doing things Brian> as simply as you suggest, but I can't remember why nor can Brian> I imagine why - I will try it again and report back here Brian> with details of any errors encountered. Unfortunately, I was right, I did have problems: type Byte_Array_Access is access all Byte_Array; pragma Convention (C,Byte_Array_Access); produces: serial.adb:107:11: warning: this access type does not correspond to C pointer and: function To_LPCVOID is new Ada.Unchecked_Conversion (Byte_Array_Access, Win32.LPCVOID); produces: serial.adb:144:04: warning: types for unchecked conversion have different sizes So I tried: Type Char_Array_Ptr is access all Interfaces.c.Char_Array; pragma Convention (C,Char_Array_Ptr); which produces: serial.adb:89:09: warning: this access type does not correspond to C pointer I still am not sure of the proper way of creating a C pointer in Ada. So far I have see advice don't user 'Access and don't use 'Address as neither of these are portable. What is the correct way? This is why my complicated solution was so complicated, I ended up: 1. Creating an aliased Byte_Array. 2. Creating a Interfaces.C.Strings.Char_Array_Access, copy access type using uchecked_conversion. 3. Converting to C pointer using Interfaces.C.Strings.To_Chars_Ptr. 4. Convert to LPCVOID using unchecked conversion. Hmmm... I wonder if what I need is system.address_to_access_conversions and/or System.Storage_Elements.To_Integer? However, all of this is complicated by the fact LPVOID and LPCVOID in Ada is defined as a subtype of System.Address in the Windows bindings, which implies the correct way to pass the parameter to Item'Address. This is also the simplest way. So I know people have said this is wrong, but I am going to assume if the windows bindings use System.Address then this method will work on Windows. -- Brian May