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.5 required=5.0 tests=BAYES_00,INVALID_MSGID, PP_MIME_FAKE_ASCII_TEXT autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII X-Google-Thread: 103376,2931eba62c045467 X-Google-Attributes: gid103376,public X-Google-Thread: 10b6ac,2931eba62c045467 X-Google-Attributes: gid10b6ac,public From: mheaney@ni.net (Matthew Heaney) Subject: Re: How to define and use an Action_Hook in ADA (using the VMS Bindings) Date: 1997/12/06 Message-ID: #1/1 X-Deja-AN: 295830817 References: <3485527F.7221E1D7@paranor.ch> Distribution: inet Organization: Estormza Software Newsgroups: comp.windows.x.motif,comp.lang.ada Date: 1997-12-06T00:00:00+00:00 List-Id: In article <3485527F.7221E1D7@paranor.ch>, Laurent St�ckli 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 (818) 985-1271