[Expat-discuss] Any suggestion please how to transfer a struct as user data ?

Gert Cuykens gert.cuykens at gmail.com
Thu Jul 19 05:02:36 CEST 2007


On 7/19/07, Nick MacDonald <nickmacd at gmail.com> wrote:
> Start with this, quickly typed by hand and not compiled, but should work:
>
>
> struct mydata
> {
>   unsigned int type;  /*  If you think you might need more than one
> type of structure */
>   unsigned int a;
>   unsigned int b;  /* or whatever */
> };
>
> typedef stuct mydata  *ptr2mydata;
>
> /* global instance */
> struct mydata myglobaldata;
>
>
> main()
> {
>   void* userDataPtr = &myglobaldata;
>   someExpatFunction(..., userDataPtr);
> }
>
>
> someExpatCallback(..., passes in userData,...)
> {
>   ptr2mydata myuserdata=(ptr2mydata)userData;  /* a cast */
>
>   printf("In function %s, userData->a=%u\n", __FUNCTION__, myuserdata->a);
>
>  /* and so on */
> }
>
> Good luck...
>

Works now :) thanks too Sebastian Pipping

static void
characterData(void *userData, const XML_Char *s, int l)
{
 PAGE *page = (PAGE *)userData;
 page->add(page,"test");
}


More information about the Expat-discuss mailing list