AssocCreate

This function creates an uninitialised association array.

Declaration

HRESULT
AssocCreate (
    CLSID clsid,
    REFIID riid,
    PVOID *ppv);

Parameters

The clsid argument provides the CLSID of a desired object.

The riid argument provides the IID of a desired interface to the object.

The ppv argument provides the address of a variable that is to receive a pointer to the desired interface.

Return Value

The function returns zero for success, else an error code.

Behaviour

If the ppv argument is NULL, the function cannot do anything useful, and fails (returning E_INVALIDARG).

If the CLSID is either CLSID_QueryAssociations or IID_IQueryAssocations, the function uses COM (through SHCoCreateInstance) to create an instance of the QueryAssociations object and to query this instance for the desired interface. Failure at this is failure for the function. In the ordinary registry configuration, instantiation is done by SHELL32 and the created object implements the following interfaces:

The created object is capable of holding and managing an array of association elements, but it is created empty of such elements. For the created object to be useful, the caller must initialise it, e.g., through the Init or SetList methods of its IQueryAssociations and IObjectWithAssociationList interfaces.

For any other CLSID, the function fails (returning E_INVALIDARG).

Earlier Versions

The preceding description is for the SHLWAPI version 6.00 from Windows Vista. The function has been greatly reduced for this version. The following elaborations are known from earlier versions.

In versions before 6.00, the function stores NULL at the address given by ppv in all cases of failure except for when ppv is itself NULL.

Versions before 6.00 support only IID_IQueryAssociations for the CLSID. For others, the function returns E_NOTIMPL.

In versions before 6.00, the created object is not creatable through COM but is an internal implementation of SHLWAPI. If the function cannot create an instance, it fails (returning E_OUTOFMEMORY). Otherwise, it queries the newly created instance for the desired interface. The only interface implemented by this internally created object is IQueryAssociations.

Support for the creatable COM object begins with version 6.00. If the CLSID is either CLSID_QueryAssociations or IID_IQueryAssocations, and the operating system is Windows XP or greater (as determined by IsOS), then the function expects that the desired object is implemented elsewhere. The function uses COM (through SHCoCreateInstance) to create an instance and to query this instance for the desired interface. Note that if the object is instantiated by a SHELL32 version 6.00 from before Windows Vista, the implemented interfaces are:

When running on earlier operating systems, the function assumes the absence of a SHELL32 that implements the QueryAssociations object. It reverts to the internal implementation, as from earlier versions.

Whatever the operating system, version 6.00 recognises the following other CLSIDs:

CLSID_AssocApplicationElement {0C2BF91B-8746-4FB1-B4D7-7C03F890B168}
CLSID_AssocClientElement {3C81E7FA-1F3B-464A-A350-114A25BEB2A2}
CLSID_AssocClsidElement {57AEA081-5EE9-4C27-B218-C4B702964C54}
CLSID_AssocFolderElement {7566DF7A-42CC-475D-A025-1205DDF4911F}
CLSID_AssocPerceivedElement {0DC5FB21-B93D-4E3D-BB2F-CE4E36A70601}
CLSID_AssocProgidElement {9016D0DD-7C41-46CC-A664-BF22F7CB186A}
CLSID_AssocShellElement {C461837F-EA59-494A-B7C6-CD040E37185E}
CLSID_AssocStarElement {0633B720-6926-404C-B6B3-923B1A501743}
CLSID_AssocSystemElement {A6C4BAAD-4AF5-4191-8685-C2C8953A148C}

These each correspond to a single type of association element, such as might be inserted into an association array obtained from using CLSID_QueryAssociations. These are internal implementations of SHLWAPI and are creatable only through this function. Support for them in Windows Vista is relocated to SHELL32 for the new function AssocCreateElement.

If the CLSID is not among these or if an instance of the object cannot be created, the function fails (returning CLASS_E_CLASSNOTAVAILABLE). Otherwise, the function queries the newly created element for the desired interface. All elements implement the following interfaces:

The created element is a blank slate, waiting to be initialised through the SetSource or SetString methods of its IObjectWithSource and IPersistString2 interfaces.

Availability

The AssocCreate function is exported by name from SHLWAPI.DLL in version 5.00 and higher. It has long been documented, but as recognising only one CLSID and one IID.