com connection points
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 PresentationTRANSCRIPT
![Page 1: COM Connection Points](https://reader036.vdocuments.site/reader036/viewer/2022062723/56813f31550346895da9d35f/html5/thumbnails/1.jpg)
COM Connection Points
主講人:虞台文
![Page 2: COM Connection Points](https://reader036.vdocuments.site/reader036/viewer/2022062723/56813f31550346895da9d35f/html5/thumbnails/2.jpg)
Content
The Client-Object-Sink Relationship IConnectionPointContainer &IConnectionPoint
Implementation using ATL/COM
![Page 3: COM Connection Points](https://reader036.vdocuments.site/reader036/viewer/2022062723/56813f31550346895da9d35f/html5/thumbnails/3.jpg)
COM Connection Points
The Client-Object-Sink Relationship
![Page 4: COM Connection Points](https://reader036.vdocuments.site/reader036/viewer/2022062723/56813f31550346895da9d35f/html5/thumbnails/4.jpg)
The Process of Connecting Source & Sink
ConnectableObject
ConnectableObject
ClientClient
Sink
Client passes sink interface pointer to connectable object.
Connectable object calls sink when appropriate.
![Page 5: COM Connection Points](https://reader036.vdocuments.site/reader036/viewer/2022062723/56813f31550346895da9d35f/html5/thumbnails/5.jpg)
One-to-Many Relationship
ConnectableObject
ConnectableObject
ClientClient
Sink
ClientClient
Sink
Sink
ClientClient
Sink
![Page 6: COM Connection Points](https://reader036.vdocuments.site/reader036/viewer/2022062723/56813f31550346895da9d35f/html5/thumbnails/6.jpg)
Many-to-One Relationship
ConnectableObject
ConnectableObject
ClientClient
SinkConnectable
Object
ConnectableObject
ConnectableObject
ConnectableObject
![Page 7: COM Connection Points](https://reader036.vdocuments.site/reader036/viewer/2022062723/56813f31550346895da9d35f/html5/thumbnails/7.jpg)
COM Connection Points
IConnectionPointContainer
&
IConnectionPoint
![Page 8: COM Connection Points](https://reader036.vdocuments.site/reader036/viewer/2022062723/56813f31550346895da9d35f/html5/thumbnails/8.jpg)
Connection Point ContainerConnection Point Container
IConnectionPointContainer &IConnectionPoint
Connection Point 1
Connection Point 2
Connection Point n
IConnectionPointContainer
IConnectionPoint
IConnectionPoint
IConnectionPoint
. .
.
![Page 9: COM Connection Points](https://reader036.vdocuments.site/reader036/viewer/2022062723/56813f31550346895da9d35f/html5/thumbnails/9.jpg)
IConnectionPointContainer
interface IConnectionPointContainer : IUnknown
{
HRESULT EnumConnectionPoints(
IEnumConnectionPoints **ppEnum) = 0;
HRESULT FindConnectionPoint(REFIID riid,
IConnectionPoint **ppCP) = 0;
};
interface IConnectionPointContainer : IUnknown
{
HRESULT EnumConnectionPoints(
IEnumConnectionPoints **ppEnum) = 0;
HRESULT FindConnectionPoint(REFIID riid,
IConnectionPoint **ppCP) = 0;
};
![Page 10: COM Connection Points](https://reader036.vdocuments.site/reader036/viewer/2022062723/56813f31550346895da9d35f/html5/thumbnails/10.jpg)
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;
};
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;
};
![Page 11: COM Connection Points](https://reader036.vdocuments.site/reader036/viewer/2022062723/56813f31550346895da9d35f/html5/thumbnails/11.jpg)
COM Connection Points
Implementation using
ATL/COM
![Page 12: COM Connection Points](https://reader036.vdocuments.site/reader036/viewer/2022062723/56813f31550346895da9d35f/html5/thumbnails/12.jpg)
Step1. Create ATL/COM Project
![Page 13: COM Connection Points](https://reader036.vdocuments.site/reader036/viewer/2022062723/56813f31550346895da9d35f/html5/thumbnails/13.jpg)
Step1. Create ATL/COM Project
![Page 14: COM Connection Points](https://reader036.vdocuments.site/reader036/viewer/2022062723/56813f31550346895da9d35f/html5/thumbnails/14.jpg)
Step2. Create ATL Object
![Page 15: COM Connection Points](https://reader036.vdocuments.site/reader036/viewer/2022062723/56813f31550346895da9d35f/html5/thumbnails/15.jpg)
Step2. Create ATL Object
![Page 16: COM Connection Points](https://reader036.vdocuments.site/reader036/viewer/2022062723/56813f31550346895da9d35f/html5/thumbnails/16.jpg)
Step2. Create ATL Object
![Page 17: COM Connection Points](https://reader036.vdocuments.site/reader036/viewer/2022062723/56813f31550346895da9d35f/html5/thumbnails/17.jpg)
Step2. Create ATL Object
![Page 18: COM Connection Points](https://reader036.vdocuments.site/reader036/viewer/2022062723/56813f31550346895da9d35f/html5/thumbnails/18.jpg)
Step2. Create ATL Object
![Page 19: COM Connection Points](https://reader036.vdocuments.site/reader036/viewer/2022062723/56813f31550346895da9d35f/html5/thumbnails/19.jpg)
Step2. Create ATL Object
![Page 20: COM Connection Points](https://reader036.vdocuments.site/reader036/viewer/2022062723/56813f31550346895da9d35f/html5/thumbnails/20.jpg)
Step2. Create ATL Object
![Page 21: COM Connection Points](https://reader036.vdocuments.site/reader036/viewer/2022062723/56813f31550346895da9d35f/html5/thumbnails/21.jpg)
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;
};};
// 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;
};};
![Page 22: COM Connection Points](https://reader036.vdocuments.site/reader036/viewer/2022062723/56813f31550346895da9d35f/html5/thumbnails/22.jpg)
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;
};};
// 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;
};};
![Page 23: COM Connection Points](https://reader036.vdocuments.site/reader036/viewer/2022062723/56813f31550346895da9d35f/html5/thumbnails/23.jpg)
Step4. Add Properties and Methods
![Page 24: COM Connection Points](https://reader036.vdocuments.site/reader036/viewer/2022062723/56813f31550346895da9d35f/html5/thumbnails/24.jpg)
Step4. Add Properties and Methods
![Page 25: COM Connection Points](https://reader036.vdocuments.site/reader036/viewer/2022062723/56813f31550346895da9d35f/html5/thumbnails/25.jpg)
Step4. Add Properties and Methods
![Page 26: COM Connection Points](https://reader036.vdocuments.site/reader036/viewer/2022062723/56813f31550346895da9d35f/html5/thumbnails/26.jpg)
Step4. Add Properties and Methods
![Page 27: COM Connection Points](https://reader036.vdocuments.site/reader036/viewer/2022062723/56813f31550346895da9d35f/html5/thumbnails/27.jpg)
Step4. Add Properties and Methods
![Page 28: COM Connection Points](https://reader036.vdocuments.site/reader036/viewer/2022062723/56813f31550346895da9d35f/html5/thumbnails/28.jpg)
Step4. Add Properties and Methods
![Page 29: COM Connection Points](https://reader036.vdocuments.site/reader036/viewer/2022062723/56813f31550346895da9d35f/html5/thumbnails/29.jpg)
Step4. Add Properties and Methods
![Page 30: COM Connection Points](https://reader036.vdocuments.site/reader036/viewer/2022062723/56813f31550346895da9d35f/html5/thumbnails/30.jpg)
Step4. Add Properties and Methods
![Page 31: COM Connection Points](https://reader036.vdocuments.site/reader036/viewer/2022062723/56813f31550346895da9d35f/html5/thumbnails/31.jpg)
Step4. Add Properties and Methods
![Page 32: COM Connection Points](https://reader036.vdocuments.site/reader036/viewer/2022062723/56813f31550346895da9d35f/html5/thumbnails/32.jpg)
Step4. Add Properties and Methods
![Page 33: COM Connection Points](https://reader036.vdocuments.site/reader036/viewer/2022062723/56813f31550346895da9d35f/html5/thumbnails/33.jpg)
Step4. Add Properties and Methods
![Page 34: COM Connection Points](https://reader036.vdocuments.site/reader036/viewer/2022062723/56813f31550346895da9d35f/html5/thumbnails/34.jpg)
Step4. Add Properties and Methods
![Page 35: COM Connection Points](https://reader036.vdocuments.site/reader036/viewer/2022062723/56813f31550346895da9d35f/html5/thumbnails/35.jpg)
Step5. Build Type Library
![Page 36: COM Connection Points](https://reader036.vdocuments.site/reader036/viewer/2022062723/56813f31550346895da9d35f/html5/thumbnails/36.jpg)
Step5. Build Type Library
![Page 37: COM Connection Points](https://reader036.vdocuments.site/reader036/viewer/2022062723/56813f31550346895da9d35f/html5/thumbnails/37.jpg)
Step5. Build Type Library
![Page 38: COM Connection Points](https://reader036.vdocuments.site/reader036/viewer/2022062723/56813f31550346895da9d35f/html5/thumbnails/38.jpg)
Step6. Implement Connection Point
![Page 39: COM Connection Points](https://reader036.vdocuments.site/reader036/viewer/2022062723/56813f31550346895da9d35f/html5/thumbnails/39.jpg)
Step6. Implement Connection Point
![Page 40: COM Connection Points](https://reader036.vdocuments.site/reader036/viewer/2022062723/56813f31550346895da9d35f/html5/thumbnails/40.jpg)
Step7. Detail the Source Code
See the Source Code for detail of other implementation.
![Page 41: COM Connection Points](https://reader036.vdocuments.site/reader036/viewer/2022062723/56813f31550346895da9d35f/html5/thumbnails/41.jpg)
Demonstration
![Page 42: COM Connection Points](https://reader036.vdocuments.site/reader036/viewer/2022062723/56813f31550346895da9d35f/html5/thumbnails/42.jpg)
Exercise
1. 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.