Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Expand Minimize

Compiler Error C3718

can only call 'event' in the context of a member function of the receiving class

The eventcan only be called from the receiving class.

The following sample generates C3718:

// C3718.cpp
#include "atlbase.h"
#include "atlcom.h"


[object, uuid("00000000-0000-0000-0000-000000000001")]
__interface I
    HRESULT f();

[event_source(com), coclass, uuid("00000000-0000-0000-0000-000000000002")]
struct E
    __event __interface I;

struct R
    void b()

    void HookAndRun(E* pE)
        __hook(&I::f, pE->GetUnknown(), &R::b);
        __raise pE->f();

int main()
    CComObject<E>* pE;

    __hook(&I::f, pE->GetUnknown(), &R::b, &r);   // C3718
    __raise pE->f();
    // try the following lines instead
    // R r;
    // r.HookAndRun(pE);

Community Additions

© 2015 Microsoft