編譯器錯誤 C3709
'function':在 __hook/__unhook 中指定事件時使用了不適當的語法
當您指定具有 __hook 或 __unhook的事件來源時,第一個參數必須是有效的事件方法,而第二個參數必須是有效的事件來源物件(不是方法)。
下列範例會產生 C3709:
// C3709.cpp
// compile with: /LD
[event_source(native)]
class CEventSrc
{
public:
__event void event1();
};
[event_receiver(native)]
class CEventRec
{
public:
void handler1()
{
}
void HookEvents(CEventSrc* pSrc)
{
__hook(bad, pSrc, CEventRec::handler1); // C3709
// Try the following line instead:
// __hook(&CEventSrc::event1, pSrc, CEventRec::handler1);
}
void UnhookEvents(CEventSrc* pSrc)
{
__unhook(&CEventSrc::event1, pSrc, CEventRec::handler1);
}
};