Microsoft KB Archive/315470

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

Article ID: 315470

Article Last Modified on 4/18/2003

-

APPLIES TO


 * Microsoft Visual C++ .NET 2002 Standard Edition

-



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 &quot;Steps to Reproduce the Behavior&quot; 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).



Steps to Reproduce the Behavior
// Test.cpp // Compiler options needed: /link /IGNOREIDL
 * 1) define _ATL_ATTRIBUTES 1

[object, uuid(&quot;DF581F10-C3B5-4246-8749-859D0CA8C988&quot;)] __interface _IBEvents { };
 * 1) include 
 * 2) include 
 * 3) define SHOW_BUG 1

[  coclass, event_source(com), uuid(&quot;DF581F10-C3B5-4246-8749-859D0CA8C989&quot;), ]
 * 1) if SHOW_BUG
 * 1) endif

class B { public: B {      Test; }   void Test {    Test2; return; }   virtual  void Test2{} public: __event __interface _IBEvents; };
 * 1) if SHOW_BUG
 * 1) 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; }

Additional query words: KbUnmanaged Native

Keywords: kbbug kbfix kbcompiler KB315470

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.