Using addon resources in an application

Updated: October 28, 2024

To use our addon resources in an application, we simply get the addon's AOResourceAccess interface using the AOGetInterface() function, call its GetResources() function, and iterate through the resources until we find one we want to look at. If we want to change one of the resources, and its AOR_TYPE_WRITABLE type flag is set, we call the interface's SetResource() function. Here are examples for getting and setting the volume:

int32_t GetVolume( AOICtrl_t *ctrl, void *ctx )
{
    AOResource_t *res;
    AOInterface_t *i;
    
    // does it have resource access?
    if ( i = AOGetInterface( ctrl, "AOResourceAccess", AORESOURCEACCESS_VERSION, 0 ) )
    {
        // does it have resources?
        if ( res = i->GetResources(ctx) )
        {
            // iterate through the resources
            for (;res->name;res++)
            {
                // is the current resource the volume?
                if ( strcmp( res->name, "Volume" ) == 0 )
                    return *( (int32_t*)res->value );
            }
        }
    }
    return -1;
}

int32_t SetVolume( AOICtrl_t *ctrl, void *ctx, int32_t volume )
{
    AOInterface_t *i;
    
    // does it have resource access?
    if ( i = AOGetInterface( ctrl, "AOResourceAccess", AORESOURCEACCESS_VERSION, 0 ) )
    {
        // try to set its Volume resource.
        return i->SetResource( ctx, "Volume", &volume );
    }
    return -1;
}