Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!cs.utexas.edu!sun-barr!newstop!exodus!argv From: argv@turnpike.Eng.Sun.COM (Dan Heller) Newsgroups: comp.windows.x.motif Subject: Re: trouble with structures and callbacks Message-ID: <3340@exodus.Eng.Sun.COM> Date: 23 Nov 90 19:33:50 GMT References: <2450@kiwi.mpr.ca> Sender: news@exodus.Eng.Sun.COM Organization: O'Reilly && Associates Lines: 36 In article <2450@kiwi.mpr.ca> baker@mprgate.mpr.ca (Sue Baker) writes: > i'm trying to pass a structure as client_data to a callback function, > and am achieving nothing but frustration. That's because you're passing a whole structure rather than a pointer to one. > struct widget_type{ /* more detail to be added */ > Widget widget_array[4]; }; /* to structure later */ > struct widget_type text; > XtAddCallback(update, XmNactivateCallback, get_text, text); The arg "text" should be "&text". e.g.: XtAddCallback(update, XmNactivateCallback, get_text, &text); void get_text(widget, text_data, cbs) Widget widget; widget_type *text_data; XmAnyCallbackStruct *cbs; { int i; char *p; /* print the text of the widget in array */ for (i = 0; i < 4; i++) { p = XmTextGetString(text_data->widget_array[i]); printf("widget_array[%d] = %s\n", i, p); XtFree(p); } } -- dan ---------------------------------------------------- O'Reilly && Associates argv@sun.com / argv@ora.com Opinions expressed reflect those of the author only.