編譯器錯誤 C3719
'interface': 介面型事件來源只能用於 COM 事件
您在非 COM 內容中宣告介面。
下列範例會產生 C3719:
// C3719a.cpp
#define _ATL_ATTRIBUTES 1
#include "atlbase.h"
#include "atlcom.h"
[module(name="MyLibrary", version="1.2", helpfile="MyHelpFile")];
[object]
__interface I {
HRESULT func1();
};
[event_source(native), coclass]
struct A {
__event __interface I; // C3719
// try the following line instead
// __event func2();
};
int main() {
}
若要修正此錯誤,請適當地套用 物件、 coclass、 event_source和 event_receiver 屬性,讓您使用介面 COM 類別的類別。 例如:
// C3719b.cpp
#define _ATL_ATTRIBUTES 1
#include <atlbase.h>
#include <atlcom.h>
[module(name="xx")];
[object, uuid("00000000-0000-0000-0000-000000000001")]
__interface I {
HRESULT f();
};
[coclass, event_source(com) , uuid("00000000-0000-0000-0000-000000000002")]
struct MyStruct {
__event __interface I;
};
[event_receiver(com)]
struct MyStruct2 {
void f() {
}
MyStruct2(I* pB) {
__hook(&I::f, pB, &MyStruct2::f);
}
};
int main()
{
}