From: Martin Krischik <krischik@users.sourceforge.net>
Subject: Re: Access to data indirection (newbie)
Date: Tue, 27 Nov 2007 09:11:13 +0100
Date: 2007-11-27T09:11:13+01:00 [thread overview]
Message-ID: <474bd14a$1@news.post.ch> (raw)
In-Reply-To: <1a812241-65fc-403a-927f-b2651b4107e3@s8g2000prg.googlegroups.com>
axtens schrieb:
> G'day everyone
>
> I have a DLL which is receiving a value that is the result of a VARPTR
> in VB6, so the value arriving is the address and the data desired can
> be found at that address.
>
> So far I've gotten as far as
>
> function HandlePointer (
> Left : in Win32.LONG)
> return Win32.LONG is
> begin
>
> end HandlePointer;
>
> which is, of course, brain-dead. Fact is, though, so far as Ada is
> concerned, I'm a newbie.
>
> So tell me, what's the syntax?
>
> Once you've figured that one out, tell me how I'd handle 'Left'
> pointing to a record of two integers, such that I can access both
> elements of the record.
Your next step would be an Unchecked_Conversion:
http://en.wikibooks.org/wiki/Ada_Programming/Type_System#Unchecked_conversion
however - for my taste you are thinking to "Low-Level" and to "C-Like".
In Ada one does not pass pointer or addresses as a pointer. Down that
road lies sorrow not satisfaction.
How about:
type Options is (Long, Short, Whatever);
type Var (Option : Options) is record
case Option is
Long =>
A_Long : Win32.LONG;
Short =>
A_Short : Win32.SHORT;
Whatever =>
A_Whatever_1 : Win32.LONG;
A_Whatever_2 : Win32.LONG;
end case;
end record:
pragma Unchecked_Union (Var);
pragma Convention (C, Var);
See: http://en.wikibooks.org/wiki/Ada_Programming/Types/record#Union
type VarPtr is access all Var;
pragma Convention (C, VarPtr);
function HandlePointer (
Left : in VarPtr)
return Win32.LONG is
begin
end HandlePointer;
pragma Export (C, HandlePointer);
or
function HandlePointer (
Left : access Var)
return Win32.LONG is
begin
end HandlePointer;
pragma Export (C, HandlePointer);
or
function HandlePointer (
Left : in Var)
return Win32.LONG is
begin
end HandlePointer;
pragma Export (C, HandlePointer);
The later might surprise you bout since the functions is declared
"export c" "in Var" is passed as a pointer.
Martin
--
mailto://krischik@users.sourceforge.net
Ada programming at: http://ada.krischik.com
next prev parent reply other threads:[~2007-11-27 8:11 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-11-27 7:10 Access to data indirection (newbie) axtens
2007-11-27 8:11 ` Martin Krischik [this message]
2007-11-27 17:32 ` Martin Krischik
2007-11-27 22:20 ` Simon Wright
2007-11-28 3:04 ` axtens
2007-11-28 3:45 ` axtens
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox