Path: utzoo!attcan!uunet!tut.cis.ohio-state.edu!ucbvax!bloom-beacon!athena.mit.edu!bjaspan From: bjaspan@athena.mit.edu (Barr3y Jaspan) Newsgroups: comp.windows.x Subject: Re: Multiple Parameters to a Callback Function Keywords: XtAddCallback ClientData Mutiple X11R4 Message-ID: <1990Mar12.180144.8218@athena.mit.edu> Date: 12 Mar 90 18:01:44 GMT References: <186@ria.ccs.uwo.ca> Sender: news@athena.mit.edu (News system) Reply-To: bjaspan@athena.mit.edu (Barr3y Jaspan) Organization: Massachusetts Institute of Technology Lines: 38 In article <186@ria.ccs.uwo.ca>, brown@csd.uwo.ca (Mike Brown) writes: > > We would like to pass multiple parameters to a function that has been > registered with XtAddCallback. Normally you can only pass one param > which then shows up as client_data. > > We've tried passing a pointer to an array of parameters (cast to XtPointer), > but that failed - the contents are scrambled. I sounds like you are doing something wrong. I've passed pointers to allocated structures as client_data to a callback before, and it worked perfectly -- after I very carefully made sure I was dereferencing everything in exactly the right way. Something like this should work: { random_type *data; data = (random_type *) malloc(n*sizeof(random_type)); magically_fill_in_array(data); XtAddCallback(widget, XtNcallback, cb_function, data); } void cb_function(w, call_data, client_data) Widget w; caddr_t *call_data, *client_data; { print_random_type(((random_type *) client_data)[0]); } Note that I just typed this off the top of my head. The point is that you can pass ANY 4-byte value as client_data, even the address of an array. Barry Jaspan, MIT-Project Athena bjaspan@athena.mit.edu