可连接对象的基本结构 I Connection Point container 可连按对象枚举器 接收器 I Connection Point 连接点对象 枚举器 I Connection Point 连接点对象 接收器
可连接对象 如何管理多个出接口 每个出接口对应一个连接点对象 通过连接点枚举器管理 对于每个出接口,如何管理多个客户连接 通过连接枚举器管理多个连接
4567,)- . *+, ()+,-./0 89)- . 4567,) ()+-./01+
实现可连接对象(源对象)(一) 枚举器 内部对象,不需要类厂和 CLSID 枚举器接口模板 class ENum<ELT T>: public IUnknown virtual HRESULT Next( ULoNG celt, ELT T*rgelt ULONG pceltFetched)=0 virtual hrESULT Skip( ULONG celt )=0; virtual HRESULT Reset( void )=0 virtual HRESULT Clone( enum<ELT T>*ppenum )=0
-. 67 12 89:;< !"! #$%&' ( )*% !+,% -+./ !"! / % -+.012345 ( )*% !*&,% -+.345 ( )*% !,(2345 ( )*% !6, !"! 345
枚举器的用法 class IStringManager: public IUnknown virtual IEnumString Enum Strings(void) void Some func(IString Manager p StringMan) String psz; TEnumStringpenum enum=p String Man->EnumStrings( while(s oK--penum->Next(1, &psz, NULL) //Do something with the string in psz and free it penum->Released return
* 7 #$%&' ( * * ,(2345 (2*0,* 7 * 73 * 8 * 4* 7 * ,3 '1,*"-944 +,:/;8/+% 33 <<=1'11 82> ,3
实现可连接对象(源对象)(一) IConnection Point Container接口 class COnnection PointContainer: public IUnknown virtual HRESULT EnumConnection Points(ENum Connection Points**) virtual HRESULT Find Connection Point(const IID*, IConnection Point**)=0; IEnum Connection Pointst接口 class eNum Connection Points: public IUnknown virtual HRESULT Next( ULONG cOnnections, IConnectionPoint**rgpcn ULONG pcFetched)=0 virtual HRESULT Skip( ULONG cOnnections)=0 virtual HRESULT Reset( void )=0 virtual HRESULT Clone( eNum Connection Points**ppEnum)=0;
6?6 #$%&' ( )*% !6?,6?345 ( )*% !026?,=/6?345 # 6?#$%&' ( )*% !+,% -+.6/6? / % -+.012345 ( )*% !*&,% -+.6345 ( )*% !,(2345 ( )*% !6,6?345