Share via


default (C++)

指示组件类中定义的自定义接口或调度接口表示默认的可编程性接口。

语法

[ default(interface1, interface2) ]

参数

interface1
默认接口,将可用于根据类(使用 default 属性定义)创建对象的脚本环境。

如果未指定默认接口,则第一个出现的非源接口用作默认接口。

interface2
(可选)默认源接口。 你还必须使用 source 属性指定此接口。

如果未指定默认源接口,则第一个源接口用作默认接口。

备注

default C++ 属性具有与 default MIDL 属性相同的功能。 default 属性还可以与 case 属性结合使用。

示例

以下代码演示如何在组件类的定义中使用 default 来将 ICustomDispatch 指定为默认可编程性接口:

// cpp_attr_ref_default.cpp
// compile with: /LD
#include "windows.h"
[module(name="MyLibrary")];

[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, default(ICustomDispatch), source(IDual), uuid("9E66A294-4365-11D2-A997-00C04FA37DDB")
]
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;
#endif
   return(0);
}

source 属性也有说明如何使用 default 的示例。

要求

特性上下文
适用于 classstruct 数据成员
可重复
必需的特性 组件类(应用于 classstruct 时)
无效的特性

有关详细信息,请参见 特性上下文

另请参阅

IDL 特性
类特性
coclass