连接点

来源:互联网 发布:sql修改语句update 编辑:程序博客网 时间:2024/04/29 22:58

一个COM组件允许有许多个连接点对象(IConnectionPoint),管理这些接点对象的接口叫做连接点容器(IconnectionPointContainer), 连接点容器接口比较简单,只有两个函数,一个是FindConnectionPoint(),表示你想查找的连接点,另一个是EnumConnectionPoint(),表示列出所有的连接点,然后你去选择使用哪个连接点,每一个连接点可以被多个客户端的接收器(Sink)连接。

Instance below:

1, New a project named Connection based ATL, select "New ATL Object" in pop menu that right click the project in ClassView. Input the name and chose the "support connection points" in tab "Attributes", now, the project model has been finished.

2, Add method for the interface , then add envent for dealing with the operation, only compile the idl file or compile the project(no need for more spend), the interface enter implement connection points and check the choice in dialog "Implement Connection Points", the frame will generate some code for connect to the event.

3,New a test project for check the correct of the COM, first import the head file and .tlb, new a class based general derived from IDispatch, then you should implement the virtual function defined in IUnknown(QueryInterface, AddRef, Release) and IDispatch(GetTypeInfo, GetTypeInfoCount, GetIDsOfName, Invoke),the important function is Invoke, it will recieve the message customer advise, according the parameter dispID you can invoke different method. 

原创粉丝点击