Events in Com and Connectable Objects

zhaozj2021-02-16  49

>> Translation from msdn

___________________

When a detection is in some things, it can notify her client. For example, a "Securities Quotes Automatic Record Receipt" program finds a change in securities price, which can notify this change to all clients. This notification process is triggered by an event.

For COM, the service object can use a COM event to trigger an event without any notification information. Objects can also use connectable objects to implement output interfaces on customers, and objects use these outlets to communicate with customers. The output interface of the COM connection object is implemented by the client program, and the customer uses an object called the receiver (SINK) to implement these interfaces and tells the interface pointer. Therefore, objects can be communicated by this and customer guarantee (equivalent to built a dedicated channel to ensure communication between objects and customers). Input interface is implemented on an object, accepting from

The call of external customers of the object; the output interface implements calls from objects on the client's receiver (SINK). Object defines the interface he want to use, customers to implement him.

The object provides his entry and implements them. The client obtains the object's entry through the object IUNKNOWN :: queryInterface method, if the object supports the operation of the client request, then execute. The output interface is also defined on the object, but he is indeed implemented on the receiver object created on the customer. Object Receiver Object Output The method on the interface, informs the changes on the customer object, triggers the event on the customer.

Connectable objects provide a universal mechanism for communications to the customer. Any notice that is willing to expose event or any type can use this technology. In addition, COM also provides a lot of dedicated receivers to inform the customer-interested specified events. For example, the IADVISINK interface can be used to notify the data and view of the customer object.

Architecture of Connectable Objects

Connectable objects are only part of the connectable object structure, which includes the following elements:

Connectable object - implements the IconnectionPointContainer interface; create at least one connection point object; define an output interface to the customer.

Customer - By querying the object IconnectionPointContainer interface determines whether the object is a connectable object; create a receiver object, implement the output interface defined by the connectable object.

Receiver Object - Implement an output interface; used to establish a connection for a connectable object.

Connection Objects - Implement the IconnectionPoint interface to manage connections to the client receiver.

The following figure shows the relationship between the customer, the connected object, the receiver object, and the connection point object:

In step 3, the connection point object calls the receiver interface method, it must obtain the specified interface by queryinterface (). Or the interface of the interface is obtained through the Advise () method at step 2.

Two enumeration objects are also included in this structure, although he is not reflected in the case. One is created by the approach to the IconnectionPointContainer interface to enumerate the connection point of the accessible object. Another method created by the IconnectionPoint interface, which is used to enumerate the current connection of the specified connection point. A connection point can support multiple connection receiver interfaces. Each time you call a method on this interface, he obtains a pointer to the specified connection receiver interface by iteration with a list with all connection points. This process is called columns.

When using connectable objects, you can make connections, each connection point, each receiver, and All Enumerators Are Separate Objects with Separate IUnknown Implementations, Separate Reference Counts, and Separate Lifetimes. Customer is always responsible after using these objects. Release his own reference count. Note: A connectable object can support multiple customers, and can also support multiple receivers from one customer.

Similarly, a receiver can also connect to multiple connectable objects.

Establish a connection between the customer and the connectable object according to the following steps:

1. Customers determines whether the object can be connected by querying the IConnectionPointContainer

of. If the return is successful, the customer points to the connectable object with a pointer.

IConnectionPointContainer interface.

An increase in reference count of the connectable object. If the object is unconnected, it does not support the output interface.

2. If the object is connected, the customer tries to get a connection point for the connectable object.

IconnectionPoint interface pointer. There are two ways to get this pointer, they are

IConnectionPointContainer :: FindConnectionPoint and

IConnectionPointContainer :: EnumConnectionPoints. If you use the latter,

Additional steps are available first. (See using iConnectionPointContainer to get more

information).

If the call is successful, the connectable objects and customers support the same output interface. Connectable object defines him

Call him, the customer realizes him. Then, the customer can communicate through the connection points within the connected object.

3. Customer calls the iconnectionPoint :: Advise method to create a connection point for the receiver and connectable object

the connection between. After calling this method, the object's connection point obtains the output pointer of the receiver.

4. IconnectionPoint :: Code in Advise calls the interface pointer that has passed

QueryInterface method to request him to connect to the interface.

The Code Inside IconnectionPoint :: Advise Calls Queryinterface

On The Interface Pointer That Is Passed in, Asking for the Specific

Interface Identifier to Which It Connects.

5. The object is called from the required receiver interface from the pointer held by his connection point.

6. Customer call iconnectionPoint :: Unadvise terminates this connection. Customer calls iConnectionPoint :: Release release the pointer. The connection object also needs to release the corresponding pointer, so the customer must call iConnectionPointContainer :: Release to release the corresponding pointer owned by the connected object.

Connectable Object Interfaces

Support for connectable object requirements support the following four interfaces:

IConnectionPointContainer on the connection objectable Object

IConnectionPoint on the connection point object

IenumConnectionPoints on an enumerator Object

IenumConnections on an enumerator Object

The next two enumeration types are standard for the IConnectionPoint * and ConnectData. (For more information on enumeration, see IEnumxxxx) In addition, connectable objects can support iProvideClassInfo and iProvideClassInfo2 to provide customer output interface. Sufficient information. The final customer must provide an implementation of a receiver output interface that is defined on the connectable object. IConnectionPointContainer, IconnectionPoint, iProvideClassInfo, definition case of interface interface:

Interface iconnectionPointContainer: iUnknown

{

HRESULT ENUMCONNECTIONPOINTS ([OUT] IENUMCONNECTIONPOINTS

** ppenum);

HRESULT FINDCONNECTIONPOINT ([in] refiid RIID,

[OUT] iconnectionPoint ** PPCP);

}

Interface IconnectionPoint: IUNKNOWN

{

HRESULT GETCONNECTIONINTERFACE ([OUT] IID * PIID;

HRESULT GETCONNECTIONPOINTCONTAINER ([OUT]

IConnectionPointContainer ** PPCPC);

HRESULT ADVISE ([in] iUnknown * punk, [out] dword * pdwcookie);

HRESULT UNADVISE ([In] DWORD DWCOOKIE);

HRESULT EnumConnections ([OUT] IEnumConnections ** Ppenum);

}

Interface iProvideClassInfo: IUNKNOWN

{

HRESULT GETCLASSIINFO ([OUT] ITYPEINFO ** PPTI);

}

Interface iProvideClassInfo2: iProvideClassInfo

{

HRESULT getGUID ();

}

转载请注明原文地址:https://www.9cbs.com/read-26960.html

New Post(0)