420 likes | 526 Views
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.
E N D
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 Client passes sink interface pointer to connectable object. Client Connectable object calls sink when appropriate.
Client Sink Connectable Object Client Sink Sink Client Sink One-to-Many Relationship
Connectable Object Connectable Object Connectable Object Client Sink Many-to-One Relationship
COM Connection Points IConnectionPointContainer &IConnectionPoint
Connection Point Container Connection Point 1 Connection Point 2 Connection Point n IConnectionPointContainer &IConnectionPoint IConnectionPointContainer IConnectionPoint IConnectionPoint . . . IConnectionPoint
IConnectionPointContainer interface IConnectionPointContainer : IUnknown { HRESULT EnumConnectionPoints( IEnumConnectionPoints **ppEnum) = 0; HRESULT FindConnectionPoint(REFIID riid, IConnectionPoint **ppCP) = 0; };
IConnectionPoint interface 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 Points Implementation using ATL/COM
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; }; };
Step7. Detail the Source Code See the Source Code for detail of other implementation.
Exercise • Implement 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.