实现可连接对象(源对象(三) 连接点和 JIConnection point接口 class COnnection Point: public IUnknown virtual HRESULT GetConnectionInterface( IID'pIlD)=0 virtual hresUlt GetConnection PointContainer I Connection PointContainer **ppCPC)=0; virtual HRESULT Advise( iunknown*pUnk, DWORD pdw Cookie)=0; virtual HRESULT Unadvise( dword dwCookie)=0; virtual HRESULT Enum Connections( IEnumConnections **ppEnum)=0 连接枚举器—实现 IEnumConnections接口 允许多个客户连接 每个连接用 dstruct ConneCtData来描述
+,2 6?#$%&' ( )*% !.6 >,==345 ( )*% !.6?6 , 6?6 6?6345 ( )*% !2(,%&'%&/=@-=2'6&345 ( )*% !%2(,=@-=2'6&345 ( )*% !6,6345 +-. $$ # =>-?@ A?@ !"!"BCD
回顾:可连接对象的基本结构 I Connection Point container 可连按对象枚举器 接收器 I Connection Point 连接点对象 枚举器 I Connection Point 连接点对象 接收器
客户与源对象建立连接过程 (1)客户请求 COnnection PointContainer接口; (2)客户调用 [ConnectionPointContainer FindConnection Pointt 到连接点对象 (3)客户调用 I Connection Point: Advise建立与接 收器的连接 (4)最后,客户调用 dIConnectionPoint: Unadvised 取消连接,并释放连接点对象
! % 34 56 &&' 7 8+, ( 56 &&)9:; + * <= 56 &&+ >?+ @AB+,
客户方基本结构 客户方实现接收器对象ink) 支持多个与可连接对象之间的连接 般只实现专用的出接口( UNknow除外) 不需要类厂、 CLSID 与客户代码紧密连接起来 建立连接 1通过 I Connection Pointcontainer接口找到连接点对象 2通过连接点对象建立连接 连接点相当于连接管理器
: EF-?GH@IJ@ KLM N! #$OP 12 GQRST@UB ;< % VW@X & @XYZ@ @X[\$@]^:
接收器的实现 class csomeEventSet: public ISome Eventset private ULONG m cRef: Reference count /other private data members public: DWORD m dw Cookie; //Connection key CSome Eventset 0 CSome EventSet(void); /IUnknown members STDMETHODIMP Querylnterface(REFIID, PPVOID STDMETHODIMP (DWORD) AddRef(void); STDMETHODIMP( DWORD) Release(void) STDMETHODIMP SomeEventFunction();
"# !!!!!! " # $%$ #&' ' ( )* + )#* ' & ,$-,.$-/0 ( )1$2//3$* ,$-,.$-/)$%$*4## )#* ,$-,.$-/)$%$* )#* ,$-,.$-/ 1 )!!!* !!!!!! 5