Compiler Error C3741

 

For the latest documentation on Visual Studio 2017 RC, see Visual Studio 2017 RC Documentation.

'class': must be a coclass when the 'layout_dependent' parameter of event_receiver = true

When layout_dependent=truefor an event_receiver class, then the class must also have the coclass attribute.

The following sample generates C3741

// C3741.cpp  
// compile with: /c  
// C3741 expected  
#define _ATL_ATTRIBUTES 1  
#include <atlbase.h>  
#include <atlcom.h>  
[module(name="xx")];  
  
[object, uuid("00000000-0000-0000-0000-000000000001")]  
__interface I{ HRESULT f(); };  
  
// Delete the following line to resolve.  
[ event_receiver(com, layout_dependent=true)]  
  
// class or struct must be declared with coclass  
// Uncomment the following line to resolve.  
// [ event_receiver(com, layout_dependent=true), coclass, uuid("00000000-0000-0000-0000-000000000002")]  
struct R : I {  
   HRESULT f(){ return 0; }  
   R(){}  
   R(I* a){ __hook(I, a); }  
};  

Show: