OpenersNotesSection(Spacer1)Details

The function (NonWLLink[WSSetUserData(), paclet:ref/c/WSSetUserData]) takes a WSUserFunction as its second argument. WSTP automatically calls the WSUserFunction at (NonWLLink[WSClose(), paclet:ref/c/WSClose]) time.

WSUserFunction is declared in the WSTP header file (RefLink[wstp.h, paclet:ref/file/wstp.h]).

OpenersPrimaryExamplesSection(Spacer1)Examples  (1)

OpenersExampleSection0(Spacer1)Basic Examples  (1)

#include <stdlib.h>
#include "wstp.h"

typedef struct foo_
{
	int member1;
} foo;


/* destroy a foo object retrieved from a link */
void c(WSTPINK lp)
{
	foo *fobj;

	fobj = WSTPUserData(lp, (WSTPUserFunction *)0);
	if(fobj == (foo *)0) return;

	free(foo);
}


/* allocate a foo object and store it in a link */

void f(WSLINK lp)
{
	foo *fobj;

	fobj = (foo *)malloc(sizeof(foo));
	if(fobj == (foo *)0)
		{ /* error allocating space for foo object */ }

	WSSetUserData(lp, (void *)fobj, c);
}

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(NonWLLink[WSSetUserData(), paclet:ref/c/WSSetUserData])  ▪  (NonWLLink[WSUserData(), paclet:ref/c/WSUserData])}})}})

({{DocumentationFooterIconsRelatedTutorial.png, ({{Tutorials}, {▪(RefLinkPlain[WSTP C API Developer Guide (Mac OS X), paclet:tutorial/WSTPDeveloperGuide-MacintoshOverview])}, {▪(RefLinkPlain[WSTP C API Developer Guide (Unix and Linux), paclet:tutorial/WSTPDeveloperGuide-UnixOverview])}, {▪(RefLinkPlain[WSTP C API Developer Guide (Windows), paclet:tutorial/WSTPDeveloperGuide-WindowsOverview])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Alphabetical Listing of WSTP C Functions, paclet:guide/AlphabeticalListingOfWSTPCFunctions])}})}})