COM Connection Points

  • View
    19

  • Download
    1

Embed Size (px)

DESCRIPTION

COM Connection Points. . Content. The Client-Object-Sink Relationship IConnectionPointContainer & IConnectionPoint Implementation using ATL/COM. COM Connection Points. The Client-Object-Sink Relationship. Connectable Object. Sink. The Process of Connecting Source & Sink. - PowerPoint PPT Presentation

Transcript

  • COM Connection Points

  • ContentThe Client-Object-Sink RelationshipIConnectionPointContainer & IConnectionPointImplementation using ATL/COM

  • COM Connection PointsThe Client-Object-Sink Relationship

  • The Process of Connecting Source & SinkClient

    Client passes sink interface pointer to connectable object.Connectable object calls sink when appropriate.

  • One-to-Many Relationship

  • Many-to-One Relationship

  • COM Connection PointsIConnectionPointContainer & IConnectionPoint

  • IConnectionPointContainer &IConnectionPointIConnectionPointContainerIConnectionPointIConnectionPointIConnectionPoint. . .

  • IConnectionPointContainer interface IConnectionPointContainer : IUnknown { HRESULT EnumConnectionPoints( IEnumConnectionPoints **ppEnum) = 0; HRESULT FindConnectionPoint(REFIID riid, IConnectionPoint **ppCP) = 0;};

  • IConnectionPointinterface IConnectionPoint : IUnknown{ HRESULT GetConnectionInterface(IID *pIID) = 0; HRESULT GetConnectionPointContainer( IConnectionPointContainer **ppCPC) = 0; HRESULT Advise(IUnknown *pUnk, DWORD *pdwCookie) = 0; HRESULT Unadvise(DWORD dwCookie) = 0; HRESULT EnumConnections(IEnumConnections **ppEnum) = 0;};

  • COM Connection PointsImplementation using ATL/COM

  • Step1. Create ATL/COM Project

  • Step1. Create ATL/COM Project

  • Step2. Create ATL Object

  • Step2. Create ATL Object

  • Step2. Create ATL Object

  • Step2. Create ATL Object

  • Step2. Create ATL Object

  • Step2. Create ATL Object

  • Step2. Create ATL Object

  • Step3. Modification of IDL// Timer.idl : IDL source for Timer.dll. . . . . . . . . . . . . . . . . . . . library TIMERLib{importlib("stdole32.tlb");importlib("stdole2.tlb");[uuid(A1EE119D-1107-4BB9-B23A-2D338F7F955F),helpstring("_IPeriodicTimerEvents Interface")]dispinterface _IPeriodicTimerEvents{properties:methods:};

    [uuid(FB1C62DE-5499-4C69-BC79-3EC6D5260D05),helpstring("PeriodicTimer Class")]coclass PeriodicTimer{[default] interface IPeriodicTimer;[default, source] dispinterface _IPeriodicTimerEvents;};};

  • Step3. Modification of IDL// Timer.idl : IDL source for Timer.dll. . . . . . . . . . . . . . . . . . . . library TIMERLib{importlib("stdole32.tlb");importlib("stdole2.tlb");[uuid(A1EE119D-1107-4BB9-B23A-2D338F7F955F),helpstring("_IPeriodicTimerEvents Interface")]interface _IPeriodicTimerEvents : IUnknown{};

    [uuid(FB1C62DE-5499-4C69-BC79-3EC6D5260D05),helpstring("PeriodicTimer Class")]coclass PeriodicTimer{[default] interface IPeriodicTimer;[default, source] interface _IPeriodicTimerEvents;};};

  • Step4. Add Properties and Methods

  • Step4. Add Properties and Methods

  • Step4. Add Properties and Methods

  • Step4. Add Properties and Methods

  • Step4. Add Properties and Methods

  • Step4. Add Properties and Methods

  • Step4. Add Properties and Methods

  • Step4. Add Properties and Methods

  • Step4. Add Properties and Methods

  • Step4. Add Properties and Methods

  • Step4. Add Properties and Methods

  • Step4. Add Properties and Methods

  • Step5. Build Type Library

  • Step5. Build Type Library

  • Step5. Build Type Library

  • Step6. Implement Connection Point

  • Step6. Implement Connection Point

  • Step7. Detail the Source CodeSee the Source Code for detail of other implementation.

  • Demonstration

  • ExerciseImplement an alarm clock object using ATL. In this COM object, you can set the alarm time, and the object will notify its sink when the time is up.