comp.lang.ada
 help / color / mirror / Atom feed
From: Brian May <bam@snoopy.apana.org.au>
Subject: Re: Thick Ada bindings to C Win32
Date: Mon, 29 Nov 2004 10:45:09 +1100
Date: 2004-11-29T10:45:09+11:00	[thread overview]
Message-ID: <sa4vfbpzgfu.fsf@snoopy.apana.org.au> (raw)
In-Reply-To: sa4u0ra7snm.fsf@snoopy.apana.org.au

>>>>> "Brian" == Brian May <bam@snoopy.apana.org.au> 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 <bam@snoopy.apana.org.au>



  parent reply	other threads:[~2004-11-28 23:45 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-11-10  2:41 Thick Ada bindings to C Win32 Brian May
2004-11-10  4:36 ` tmoran
2004-11-10 19:31 ` Jeffrey Carter
2004-11-12  1:51   ` Brian May
2004-11-12 12:09 ` Nick Roberts
2004-11-12 17:57   ` tmoran
2004-11-12 18:50     ` Martin Krischik
2004-11-12 23:29   ` Brian May
2004-11-13  0:51     ` Jeffrey Carter
2004-11-25 23:19       ` Brian May
2004-11-26  9:50         ` Martin Krischik
2004-11-26 12:23           ` Frank J. Lhota
2004-11-26 19:19         ` Jeffrey Carter
2004-11-27 23:56           ` Brian May
2004-11-28 18:57             ` Jeffrey Carter
2004-11-28 23:45             ` Brian May [this message]
2004-11-29  7:50               ` Message-ID: <sa4vfbpzgfu.fsf@snoo tmoran
2004-11-29 14:34               ` Thick Ada bindings to C Win32 Frank J. Lhota
replies disabled

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