In extensions, stubs first should check to see if they have initialized themselves on a connection. If they have not, they then should call XInitExtension() to attempt to initialize themselves on the connection.
If the extension needs to be informed of GC/font allocation or deallocation or if the extension defines new event types, the functions described here allow the extension to be called when these events occur.
The XExtCodes structure returns the information from XInitExtension() and is defined in X11/Xlib.h :
typedef struct _XExtCodes { /* public to extension, cannot be changed */
int extension; /* extension number */
int major_opcode; /* major op-code assigned by server */
int first_event; /* first event number for the extension */
int first_error; /* first error number for the extension */
} XExtCodes;
To allocate an XExtCodes, use XAddExtension().