Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.

default (C++)

Indicates that the custom or dispinterface defined within a coclass represents the default programmability interface.

[ default( 
) ]


The default interface that will be made available to scripting environments that create an object based on the class defined with the default attribute.

If no default interface is specified, the first occurrence of a nonsource interface is used as the default.


The default source interface. You must also specify this interface with the source attribute.

If no default source interface is specified, the first source interface is used as the default.

The default C++ attribute has the same functionality as the default MIDL attribute. The default attribute is also used with the case attribute.

The following code shows how default is used on the definition of a coclass to specify ICustomDispatch as the default programmability interface:

// cpp_attr_ref_default.cpp
// compile with: /LD
#include "windows.h"

[object, uuid("9E66A290-4365-11D2-A997-00C04FA37DDB")]
__interface ICustom {
   HRESULT Custom([in] long l, [out, retval] long *pLong);

[dual, uuid("9E66A291-4365-11D2-A997-00C04FA37DDB")] 
__interface IDual {
   HRESULT Dual([in] long l, [out, retval] long *pLong);

[object, uuid("9E66A293-4365-11D2-A997-00C04FA37DDB")]
__interface ICustomDispatch : public IDispatch {
   HRESULT Dispatch([in] long l, [out, retval] long *pLong);

[   coclass,
class CClass : public ICustom, public IDual, public ICustomDispatch {
   HRESULT Custom(long l, long *pLong) { return(S_OK); }
   HRESULT Dual(long l, long *pLong) { return(S_OK); }
   HRESULT Dispatch(long l, long *pLong) { return(S_OK); }

int main() {
#if 0 // Can't instantiate without implementations of IUnknown/IDispatch
   CClass *pClass = new CClass;

   long llong;

   pClass->custom(1, &llong);
   pClass->dual(1, &llong);
   pClass->dispinterface(1, &llong);
   pClass->dispatch(1, &llong);

   delete pClass;

The source attribute also has an example of how to use default.

Attribute Context

Applies to

class, struct, data member



Required attributes

coclass (when applied to class or struct)

Invalid attributes


For more information, see Attribute Contexts.

Community Additions

© 2015 Microsoft