ATL Controls, Visual Basic 5.0, and the IQuickActivate Interface

Robert Coleridge
MSDN Content Development Group

Over the past few months I have received numerous questions in regard to the IQuickActivate interface in an Active Template Library (ATL) control used with Microsoft Visual Basic 5.0. I would like to take a few minutes and explain what the problems are and how to fix them.

What is the IQuickActivate interface? This is an interface which, if supported by the control, allows for faster load times. It allows controls and containers to avoid performance bottlenecks on loading controls. It combines the load-time or initialization-time handshaking between the control and its container into a single call.

If an ATL control implements the IQuickActivate interface it must also implement the IPropertyNotifySink interface. This interface, IPropertyNotifySink, is implemented by a sink object to receive notifications about property changes from an object that supports IPropertyNotifySink as an "outgoing" interface.

Problem

The problem manifests itself after you have inserted an ATL ActiveX control into Visual Basic 5.0 and then run the program. You will get the following message:

Unhandled exception in Vb5.exe: 0xC0000005: Access Violation

You will get the same message when you try to delete the control.

Solution 1 (recommended)

Install the latest service pack for Visual Studio 97. This can be found at http://www.microsoft.com/vstudio/sp/.

Solution 2

Remove the dependence on the IQuickActivate interface. To remove IQuickActivate support, comment out the lines containing IQuickActivateImpl in the control's class inheritance list and in the COM interface map.

For example, if you generate a full control called MyCtl with the ATL Object Wizard, then go to MyCtl.h and comment out the line containing IQuickActivateImpl in the CMyCtl class inheritance list:

class ATL_NO_VTABLE CMyCtl :
  ...
  // public IQuickActivateImpl<CMyCtl>
Also, comment out the line containing IQuickActivateImpl in the COM interface map in MyCtl.h: 
  BEGIN_COM_MAP(CMyCtl)
  ...

  // COM_INTERFACE_ENTRY_IMPL(IQuickActivate)

Solution 3

Add support for IPropertyNotifySink. Derive the control class from IPropertyNotifySinkCP and add IPropertyNotifySink to the connection point map.

// derive your control class from IPropertyNotifySinkCP
   class CPolyCtl : public IPropertyNotifySinkCP<CPolyCtl>
   {
   ...
   }
   // add IPropertyNotifySink to the connection point map
   BEGIN_CONNECTION_POINT_MAP(CPolyCtl)

     CONNECTION_POINT_ENTRY(IID_IPropertyNotifySink)
   END_CONNECTION_POINT_MAP()

To summarize: When the IQuickActivate interface in an ATL ActiveX control is used with Visual Basic 5.0, it causes an error that needs to be corrected in one of three ways:

  1. Install the latest Visual Studio service pack,

  2. Remove the IQuickActivate interface, or

  3. Add the IPropertyNotifySink interface.