Caution: This version of this document is no longer maintained. For the latest documentation, see http://www.qnx.com/developers/docs.

ApGetInstance()

Get the module link instance pointer for a widget

Synopsis:

#include <Ap.h>

PtWidget_t *ApGetInstance( PtWidget_t *widget );

Arguments:

widget
A pointer to the widget that you want to get the module link instance pointer for.

Library:

Ap

Description:

ApGetInstance() is used to obtain the widget's module link instance pointer. For most modules, PhAB generates manifests that let you access the widgets within that module directly, provided only one instance of the module exists at a time.

Because window modules allow you to have multiple instances, you can't always use the direct access manifests; the manifest will only be valid for the last instance of the window. For windows, you may need either to save the module link_instance pointer when creating the window, or to use this function within the callback to determine the origin of the callback.

Returns:

The module link instance pointer for the widget, or NULL if it can't be determined.

Examples:

PtArg_t        args[1];

mywindow_callback( PtWidget_t *widget, ... )
{
    PtWidget_t  *window;

    /* from which window did this come? */
    if ( window = ApGetInstance( widget ) ) {
        /* set the widget selected to red */
        PtSetArg( &args[0], Pt_ARG_FILL_COLOR, 
                  Pg_RED, 0 );
        PtSetResources( ApGetWidgetPtr( window,
                        ApName( widget ) ), 1, args );
    }

    return( Pt_CONTINUE );
}

Note: An interesting observation about this callback example is that it doesn't know which window is being modified or which widget gets changed. It acts on whatever widget the user selects.

Classification:

Photon

Safety:
Interrupt handler No
Signal handler No
Thread No

See also:

ApGetWidgetPtr()

Handling multiple instances of a window in the Working with Code chapter of the Photon Programmer's Guide