QueryAssociations

SHELL32 provides a creatable class object that can represent all the registry settings that apply to an association. Instances can be created using such well-documented COM functions as CoCreateInstance, by anyone who knows the CLSID:

CLSID_QueryAssociations {A07034FD-6CAA-4954-AC3F-97A27216F98A}

A convenient way to get this creation done in one step is provided by the SHLWAPI function AssocCreate. Indeed, before SHELL32 version 6.00, this SHLWAPI function was the only way to create the object since it was not then creatable through COM.

The QueryAssociations object implements the following interfaces:

Note that only the last of these is documented. Its methods provide for initialising the object, i.e., to tell it what association to model, and for querying the association for particular settings. The undocumented interfaces provide much greater control of the object’s initialisation and of what can be queried.

The object is an array of association elements. Each element models settings from one registry key (and its subkeys). The array models that when an association is queried for a particular setting, the answer may come from any of several keys in a reliable order of precedence. Initialisation is therefore a matter of creating the elements for an association and inserting them into the array in the desired order.

The Init method of the object’s IQueryAssociations interface fills the array with a standard assortment of elements for an association of its broad type. Note that a new object is not needed for each association that is to be queried: the one object can just be re-initialised.

To exercise more control, e.g., to set up a non-standard order of precedence, create elements individually with the AssocCreate function, then implement an IEnumAssociationElements interface for them as a set, and insert them into the array by calling the InsertElements method of the IAssociationArrayInitialize interface. Windows Vista changes the machinery but eases the work (and legitimises the notion of setting up a custom order of precedence) by exporting a new function, AssocCreateForClasses. For cases not covered by the new function, create each element by calling the AssocCreateElement function, then implement an IAssociationList interface for them, and insert them into the array by calling the SetList method of the IObjectWithAssociationList interface.

Availability

The QueryAssociations createable class is implemented in SHELL32 version 6.00 and higher.