Skip to content

Latest commit

 

History

History
49 lines (36 loc) · 1.27 KB

compiler-warning-level-1-c4683.md

File metadata and controls

49 lines (36 loc) · 1.27 KB
description title ms.date f1_keywords helpviewer_keywords ms.assetid
Learn more about: Compiler Warning (level 1) C4683
Compiler Warning (level 1) C4683
08/27/2018
C4683
C4683
e6e77364-dba1-46dd-ae1d-03da23070bce

Compiler Warning (level 1) C4683

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

Remarks

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 situations:

  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.

Example

The following sample generates C4683 and shows how to fix it:

// C4683.cpp
// compile with: /W1 /LD
#define _ATL_ATTRIBUTES 1
#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
};