共用方式為


default (C++)

表示 coclass 內定義的自訂或 dispinterface,用以代表預設可程式性介面。

語法

[ default(interface1, interface2) ]

參數

interface1
預設介面,可供腳本環境使用,這些環境會根據以 default 屬性定義的類別來建立物件。

如果未指定預設介面,預設會使用第一個出現的非來源介面。

interface2
(選擇性)預設來源介面。 您也必須使用 source 屬性來指定此介面。

如果未指定預設來源介面,預設會使用第一個來源介面。

備註

defaultC++ 屬性的功能與 預設 MIDL 屬性相同。 屬性 default 也會與 case 屬性搭配 使用。

範例

下列程式碼示範如何在 default coclass 的定義上使用 ,以指定 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);
}

來源 屬性也有如何使用 default 的範例。

需求

屬性內容
適用於 class、、 struct 資料成員
可重複 No
必要屬性 coclass (套用至 classstruct 時)
無效屬性

如需詳細資訊,請參閱 屬性內容

另請參閱

IDL 屬性
類別屬性
coclass