comp.lang.ada
 help / color / mirror / Atom feed
* How to define and use an Action_Hook in ADA (using the VMS Bindings)
@ 1997-12-03  0:00 Laurent St�ckli
  1997-12-06  0:00 ` Matthew Heaney
  0 siblings, 1 reply; 2+ messages in thread
From: Laurent St�ckli @ 1997-12-03  0:00 UTC (permalink / raw)



Hi,

I'm trying to define an Actionhook in ADA ( ;-( not my choice)  using
the DEC VMS ADA Motif-Bindings and I always get exceptions
(constraint_error or access_violation) at the execution of the procedure
when the parameters action_name or params are used.

the definition in C is :

typedef void (*XtActionHookProc)(Widget, XtPointer, String, XEvent*,
String*, Cardinal*);
Widget w;
XtPointer client_data;
String action_name;
XEvent* event;
String* params;
Cardinal* num_params;

Does anyone know what corresponding types I should use ? 

TIA

Laurent

-- 
--------------------------------------------------------------------
Laurent STOECKLI | stoecklil@post.ch - stoeckli@worldcom.ch	
Grand-Places 18	 | private: +41 37 322.12.32	
1700 Fribourg    | office:  +41 31 828.92.59
--------------------------------------------------------------------




^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: How to define and use an Action_Hook in ADA (using the VMS Bindings)
  1997-12-03  0:00 How to define and use an Action_Hook in ADA (using the VMS Bindings) Laurent St�ckli
@ 1997-12-06  0:00 ` Matthew Heaney
  0 siblings, 0 replies; 2+ messages in thread
From: Matthew Heaney @ 1997-12-06  0:00 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 2581 bytes --]


In article <3485527F.7221E1D7@paranor.ch>, Laurent St�ckli
<STOECKLI@paranor.ch> wrote:

>I'm trying to define an Actionhook in ADA ( ;-( not my choice)  using
>the DEC VMS ADA Motif-Bindings and I always get exceptions
>(constraint_error or access_violation) at the execution of the procedure
>when the parameters action_name or params are used.
>
>the definition in C is :
>
>typedef void (*XtActionHookProc)(Widget, XtPointer, String, XEvent*,
>String*, Cardinal*);
>Widget w;
>XtPointer client_data;
>String action_name;
>XEvent* event;
>String* params;
>Cardinal* num_params;
>
>Does anyone know what corresponding types I should use ? 

You must tell us which version of Ada you're using: Ada 83 or Ada 95?

Here's a low-level approach you can use in Ada 83:

type Address_Array is array (Natural range 0 .. 1_000) of System.Address;

type Address_Array_Access is access Address_Array;
for Address_Array'Storage_Size use 0;

type Cardinal_Access is access Cardinal;
for Cardinal_Access'Storage_Size use 0;

procedure Action_Hook
  (W : Widget;
   Client_Data    : System.Address;  -- or int32
   Action_Name : System.Address;
   Event             : XEvent_Access;
   Params          : Address_Array_Access;
   Num_Params : Cardinal_Access);

pragma Interface (...);

Actually, there's a hipper way to do this using the mechanism parameters of
the pragma Interface, but what I've shown above will work too.

If you want to use this data, you'll have to declare an object with an
address clause, using the value of address passed in as an argument to the
action hook.  (You could use System.Fetch_From_Address too; I kinda liked
that handy little function.)  For the strings, you have to find the
terminating null to get the length.  For example,

function To_String (Address : System.Address) return String is
   Length : Natural := 0;
   function To_Character is new Fetch_From_Address (Character);
begin
   while To_Character (Address) /= ASCII.NUL loop
      Length := Length + 1;
   end loop;

   declare
      S : String (1 .. Length);
      for S use at Address;
   begin
      return S;
   end;
end To_String;

You may be having trouble with interpreting an array passed in.  Under no
circumstances should you try to use an unconstrained array type.  Use a
pointer to a constrained array type.

If you need an Ada 95 solution or have any other questions about VMS X
programming in Ada, let me know.

--------------------------------------------------------------------
Matthew Heaney
Software Development Consultant
<mailto:matthew_heaney@acm.org>
(818) 985-1271




^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~1997-12-06  0:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-12-03  0:00 How to define and use an Action_Hook in ADA (using the VMS Bindings) Laurent St�ckli
1997-12-06  0:00 ` Matthew Heaney

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