Upload
albin
View
24
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
Citation preview
COM Connection Points
主講人:虞台文
Content
The Client-Object-Sink Relationship IConnectionPointContainer &IConnectionPoint
Implementation using ATL/COM
COM Connection Points
The Client-Object-Sink Relationship
The Process of Connecting Source & Sink
ConnectableObject
ConnectableObject
ClientClient
Sink
Client passes sink interface pointer to connectable object.
Connectable object calls sink when appropriate.
One-to-Many Relationship
ConnectableObject
ConnectableObject
ClientClient
Sink
ClientClient
Sink
Sink
ClientClient
Sink
Many-to-One Relationship
ConnectableObject
ConnectableObject
ClientClient
SinkConnectable
Object
ConnectableObject
ConnectableObject
ConnectableObject
COM Connection Points
IConnectionPointContainer
&
IConnectionPoint
Connection Point ContainerConnection Point Container
IConnectionPointContainer &IConnectionPoint
Connection Point 1
Connection Point 2
Connection Point n
IConnectionPointContainer
IConnectionPoint
IConnectionPoint
IConnectionPoint
. .
.
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;
};
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;
};
COM Connection Points
Implementation 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;
};};
// 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;
};};
// 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 Code
See the Source Code for detail of other implementation.
Demonstration
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.