1 / 42

COM Connection Points

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.

albin
Download Presentation

COM Connection Points

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. COM Connection Points 主講人:虞台文

  2. Content • The Client-Object-Sink Relationship • IConnectionPointContainer &IConnectionPoint • Implementation using ATL/COM

  3. COM Connection Points The Client-Object-Sink Relationship

  4. Connectable Object Sink The Process of Connecting Source & Sink Client passes sink interface pointer to connectable object. Client Connectable object calls sink when appropriate.

  5. Client Sink Connectable Object Client Sink Sink Client Sink One-to-Many Relationship

  6. Connectable Object Connectable Object Connectable Object Client Sink Many-to-One Relationship

  7. COM Connection Points IConnectionPointContainer &IConnectionPoint

  8. Connection Point Container Connection Point 1 Connection Point 2 Connection Point n IConnectionPointContainer &IConnectionPoint IConnectionPointContainer IConnectionPoint IConnectionPoint . . . IConnectionPoint

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

  10. 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; };

  11. COM Connection Points Implementation using ATL/COM

  12. Step1. Create ATL/COM Project

  13. Step1. Create ATL/COM Project

  14. Step2. Create ATL Object

  15. Step2. Create ATL Object

  16. Step2. Create ATL Object

  17. Step2. Create ATL Object

  18. Step2. Create ATL Object

  19. Step2. Create ATL Object

  20. Step2. Create ATL Object

  21. 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; }; };

  22. 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; }; };

  23. Step4. Add Properties and Methods

  24. Step4. Add Properties and Methods

  25. Step4. Add Properties and Methods

  26. Step4. Add Properties and Methods

  27. Step4. Add Properties and Methods

  28. Step4. Add Properties and Methods

  29. Step4. Add Properties and Methods

  30. Step4. Add Properties and Methods

  31. Step4. Add Properties and Methods

  32. Step4. Add Properties and Methods

  33. Step4. Add Properties and Methods

  34. Step4. Add Properties and Methods

  35. Step5. Build Type Library

  36. Step5. Build Type Library

  37. Step5. Build Type Library

  38. Step6. Implement Connection Point

  39. Step6. Implement Connection Point

  40. Step7. Detail the Source Code See the Source Code for detail of other implementation.

  41. Demonstration

  42. 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.

More Related