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

Nick MacDonald nickmacd at gmail.com
Thu Jul 19 04:39:50 CEST 2007


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...


More information about the Expat-discuss mailing list