aggregatable

Indicates that the class supports aggregation.

[ aggregatable(  
   value 
) ]

Parameters

  • value (optional)
    A parameter to indicate when the COM object can be aggregated:

    • never   The COM object cannot be aggregated.

    • allowed   The COM object can be created directly or it can be aggregated. This is the default.

    • always   The COM object cannot be created directly and can only be aggregated. When you call CoCreateInstance for this object, you must specify the aggregating object's IUnknown interface (the controlling IUnknown).

Remarks

The aggregatable C++ attribute has the same functionality as the aggregatable MIDL attribute. This means that the compiler will pass the aggregatable attribute through to the generated .idl file.

This attribute requires that the coclass, progid, or vi_progid attribute (or another attribute that implies one of these) also be applied to the same element. If any single attribute is used, the other two are automatically applied. For example, if progid is applied, vi_progid and coclass are also applied.

ATL Projects

If this attribute is used within a project that uses ATL, the behavior of the attribute changes. In addition to the previously described behavior, the attribute also adds one of the following macros to the target class:

Parameter value

Inserted macro

Never

DECLARE_NOT_AGGREGATABLE

Allowed

DECLARE_POLY_AGGREGATABLE

Always

DECLARE_ONLY_AGGREGATABLE

Example

// cpp_attr_ref_aggregatable.cpp
// compile with: /LD
#define _ATL_ATTRIBUTES
#include "atlbase.h"
#include "atlcom.h"

[module(name="MyModule")];

[ coclass, aggregatable(allowed),
  uuid("1a8369cc-1c91-42c4-befa-5a5d8c9d2529")]
class CMyClass {};

Requirements

Attribute Context

Applies to

class, struct

Repeatable

No

Required attributes

One or more of the following: coclass, progid, or vi_progid.

Invalid attributes

None

For more information about the attribute contexts, see Attribute Contexts.

See Also

Reference

Aggregation

Other Resources

IDL Attributes

Class Attributes

Typedef, Enum, Union, and Struct Attributes

Attributes Samples