You are currently offline, waiting for your internet to reconnect

FIX: Access Violation Firing an Error Event in OLE Control

This article was previously published under Q141661
Retired KB Content Disclaimer
This article was written about products for which Microsoft no longer offers support. Therefore, this article is offered "as is" and will no longer be updated.
An access violation occurs when the error event is fired in an OLE Control.This occurs on the first firing of an error event in Release builds andonly after several firings in Debug builds.
An invalid "this" pointer is being loaded off the stack on a call toExternalRelease() at the end of COleControl::FireEvent().
Microsoft has confirmed this to be a bug in the Microsoft products listedat the beginning of this article. This bug was corrected in MicrosoftVisual C++, 32-bit Edition, version 4.0.
To reproduce this problem, add the stock Error event to an OLE Controlusing ClassWizard's OLE Events tab. The name given the member function tofire the event will be FireError. In the OnLButtonDown handler of the OLEControl, call FireError() and pass the following parameters:
FireError(CTL_E_OUTOFMEMORY, " ");
This causes the SCODE of the error to be 0x800A0007 (CTL_E_OUTOFMEMORY),and the description string to be " ", a single space followed by a NULLbyte. The rest of the parameters will be defaults.

Now, run the test container, insert your control, and click the control'sclient area. In Release builds, this causes an access violation on thefirst occurrence of the event. In Debug, it takes several occurrencesbefore the access violation is seen.

Sample Code

Below is the OnLButtonDown handler for the Circ3 tutorial sample, modifiedto call the error event.
/* Compile options needed:*/ void CCirc3Ctrl::OnLButtonDown(UINT nFlags, CPoint point){   /*  Comment the tutorial.        CDC* pdc;   // Flash the color of the control if within the           ellipse.   if (InCircle(point))   {      pdc = GetDC();      FlashColor(pdc);      ReleaseDC(pdc);      // Fire the ClickIn event      FireClickIn(point.x, point.y);   }   else      // Fire the ClickOut event      FireClickOut();        */         // Here's the call.   FireError(CTL_E_OUTOFMEMORY, " ");   COleControl::OnLButtonDown(nFlags, point);}				
2.00 2.10 2.20 3.00 3.10 3.20

Article ID: 141661 - Last Review: 10/24/2003 14:50:14 - Revision: 2.0

  • Microsoft Visual C++ 2.0 Professional Edition
  • Microsoft Visual C++ 2.1
  • Microsoft Visual C++ 2.2
  • kbbug kbctrl kbfix KB141661