編譯器錯誤 C3706
'function' : 必須是 COM 介面才能引發 COM 事件
您用來引發 COM 事件的事件介面必須是 COM 介面。 在此情況下,介面應該使用 Visual C++ 屬性來定義,或使用具有 #import embedded_idl 屬性的類型連結庫 #import 匯入。
請注意, #include
使用 COM 事件需要下列範例中顯示的 ATL 頭檔行。 若要修正此錯誤,請將下列其中一個屬性套用至介面定義,讓 IEvents
COM 介面成為 COM 介面: object、 dual 或 dispinterface。
如果介面來自 MIDL 所產生的頭檔,編譯程式將無法將其辨識為 COM 介面。
下列範例會產生 C3706:
// C3706.cpp
// compile with: /c
// C3706 expected
#define _ATL_ATTRIBUTES 1
#include <atlbase.h>
#include <atlcom.h>
#include <atlctl.h>
[module(dll, name="idid", uuid="12341234-1234-1234-1234-123412341234")];
// Uncomment the following line to resolve.
// [object, uuid="12341234-1234-1234-1234-123412341237"]
__interface IEvents : IUnknown {
HRESULT event1(/*[in]*/ int i); // uncomment [in]
};
[dual, uuid="12341234-1234-1234-1234-123412341235"]
__interface IBase {
HRESULT fireEvents();
};
[coclass, event_source(com), uuid="12341234-1234-1234-1234-123412341236"]
class CEventSrc : public IBase {
public:
__event __interface IEvents;
HRESULT fireEvents() {
HRESULT hr = IEvents_event1(123);
return hr;
}
};