Compiler Warning (level 1) C4683
Collapse the table of content
Expand the table of content
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer

Compiler Warning (level 1) C4683

' function ': event source has an 'out'-parameter; exercise caution when hooking multiple event handlers

If more than one event sink is listening to a COM event source, the value of an out parameter may be ignored.

Be aware that a memory leak will occur in the following situation:

  1. If a method has an out parameter that is internally allocated, for example a BSTR *.

  2. If the event has more than one handler (is a multicast event)

The reason for the leak is that the out parameter will be set by more than one handler, but returned to the call site only by the last handler.

The following sample generates C4683:

// C4683.cpp
// compile with: /W1 /LD
#include "atlbase.h"
#include "atlcom.h"

[ module(name="xx") ];

[ object ]
__interface I {
   HRESULT f([out] int* pi);
   // try the following line instead
   // HRESULT f(int* pi);

[ coclass, event_source(com) ]
struct E {
   __event __interface I;   // C4683
© 2016 Microsoft