Share via


IDispEventSimpleImpl Class

This class provides implementations of the IDispatch methods, without getting type information from a type library.

template < 
   UINT nID, 
   class T, 
   const IID* pdiid 
> 
class ATL_NO_VTABLE IDispEventSimpleImpl : 
   public _IDispEventLocator<nID, pdiid>

Parameters

  • nID
    A unique identifier for the source object. When IDispEventSimpleImpl is the base class for a composite control, use the resource ID of the desired contained control for this parameter. In other cases, use an arbitrary positive integer.

  • T
    The user's class, which is derived from IDispEventSimpleImpl.

  • pdiid
    The pointer to the IID of the event dispinterface implemented by this class.

Remarks

IDispEventSimpleImpl provides a way of implementing an event dispinterface without requiring you to supply implementation code for every method/event on that interface. IDispEventSimpleImpl provides implementations of the IDispatch methods. You only need to supply implementations for the events that you are interested in handling.

IDispEventSimpleImpl works in conjunction with the event sink map in your class to route events to the appropriate handler function. To use this class:

  • Add a SINK_ENTRY_INFO macro to the event sink map for each event on each object that you want to handle.

  • Supply type information for each event by passing a pointer to an _ATL_FUNC_INFO structure as a parameter to each entry. On the x86 platform, the _ATL_FUNC_INFO.cc value must be CC_CDECL with the callback function calling method of __stdcall. (Smart Device Developers, see Smart Device Developer Notes below.)

  • Call DispEventAdvise to establish the connection between the source object and the base class.

  • Call DispEventUnadvise to break the connection.

You must derive from IDispEventSimpleImpl (using a unique value for nID) for each object for which you need to handle events. You can reuse the base class by unadvising against one source object then advising against a different source object, but the maximum number of source objects that can be handled by a single object at one time is limited by the number of IDispEventSimpleImpl base classes.

IDispEventSimplImpl provides the same functionality as IDispEventImpl, except it does not get type information about the interface from a type library. The wizards generate code based only on IDispEventImpl, but you can use IDispEventSimpleImpl by adding the code by hand. Use IDispEventSimpleImpl when you don't have a type library describing the event interface or want to avoid the overhead associated with using the type library.

Note

IDispEventImpl and IDispEventSimpleImpl provide their own implementation of IUnknown::QueryInterface enabling each IDispEventImpl or IDispEventSimpleImpl base class to act as a separate COM identity while still allowing direct access to class members in your main COM object.

CE ATL implementation of ActiveX event sinks only supports return values of type HRESULT or void from your event handler methods; any other return value is unsupported and its behavior is undefined.

For more information, see Supporting IDispEventImpl.

Requirements

Header: atlcom.h

Smart Device Developer Notes

IDispEventSimpleImpl requires the _ATL_FUNC_INFO.cc member to be CC_STDCALL, but CE only supports CC_CDECL. Although this is an apparent contradiction, for Pocket PC, the callback works regardless of the _ATL_FUNC_INFO.cc value or the callback method's calling convention. The following example demonstrates a sample event handler for Pocket PC:

_ATL_FUNC_INFO Event1Info1 = { CC_CDECL, VT_EMPTY, 1, { VT_I4 } };

class CEventHandler :
   public IDispEventSimpleImpl<1234, CEventHandler, &__uuidof(DMyEventMakerEvents)>
{
public:
   BEGIN_SINK_MAP(CEventHandler)
      SINK_ENTRY_INFO(1234, __uuidof(DMyEventMakerEvents), 1, 
         &CEventHandler::OnEvent1, &Event1Info1)
   END_SINK_MAP()

   void __stdcall  OnEvent1(LONG l)
   {
      if (l != 445533)
      {
         OutputDebugString(L"l is not 445533\n");
      }
   }

   HRESULT Advise1234(IUnknown * punk) 
   {
      return IDispEventSimpleImpl<1234, CEventHandler, 
         &__uuidof(DMyEventMakerEvents)>::DispEventAdvise(punk);
   }
};

See Also

Reference

_ATL_FUNC_INFO Structure

IDispatchImpl Class

IDispEventImpl Class

SINK_ENTRY_INFO

Other Resources

IDispEventSimpleImpl Members

ATL Class Overview