FIX: Calling Virtual Functions in a COM Event Source May Cause Run-time Exception Errors (315470)



The information in this article applies to:

  • Microsoft Visual C++ .NET (2002)

This article was previously published under Q315470

SYMPTOMS

If you call virtual functions in a Component Object Model (COM) event source, as shown in the code sample in the "Steps to Reproduce the Behavior" section of this article, you receive run-time exception errors when you run the program.

RESOLUTION

To work around this problem, do one of the following:
  • Remove virtual keywords, such as the virtual keyword for Test2 in Test.cpp.

    -or-
  • Remove the event code. For example, in Test.cpp, define SHOW_BUG to be 0.

STATUS

Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article. This bug was corrected in Microsoft Visual C++ .NET (2003).

MORE INFORMATION

Steps to Reproduce the Behavior

// Test.cpp
// Compiler options needed: /link /IGNOREIDL
#define _ATL_ATTRIBUTES 1

#include <atlbase.h>
#include <atlcom.h>
#define SHOW_BUG 1
[object, uuid("DF581F10-C3B5-4246-8749-859D0CA8C988")]
  __interface _IBEvents
{
};

[   coclass,
#if SHOW_BUG
   event_source(com),
#endif
    uuid("DF581F10-C3B5-4246-8749-859D0CA8C989"),
]

class B
{
public:
    B()
    {
       Test();
    }
    void Test()
   {
     Test2();
     return;
   }
    virtual  void Test2(){}
public:
#if SHOW_BUG
   __event __interface _IBEvents;
#endif
};

class D : public B
{
   ULONG __stdcall AddRef() {return 1;}
   ULONG __stdcall Release() {return 1;}
   HRESULT __stdcall QueryInterface(REFIID, void**) 
  { 
   return S_OK;
  }
};

int main()
{
   B* pB = new D();
}
				

Modification Type:MajorLast Reviewed:4/18/2003
Keywords:kbbug kbCompiler kbfix KB315470