About ATL automatic generated event excitation function Fire

xiaoxiao2021-03-06  43

For example, the function definition in IDL: [ID (3), Helpstring ("Method TCB83")] HRESULT TCB83 ([OUT] VARIANT * VARREF); the corresponding event excitation function and code description: HRESULT Fire_TCB83 (...) { / / Define a Variant's intelligent type used to store the callback result ccomvariant varresult; // define a pointer T * pt = static_cast (this); int nConnectionIndex; // Defines a variant intelligence type Array, this array uses // to store the parameters of the invoking event response function, and the value returned after the call ([OUT] or [IN, OUT] is still placed in the corresponding position, Number of returned values. Ccomvariant * pvars = new ccomvariant [1]; // m_VEC is a package class of a smart interface pointer array, and an array is a client-side event interface pointer, actually //. After the server with connection points, the method to be called similar to Adviser is to transfer yourself to the server and put into this array. The server // excitation event is actually used in the use of arrays. The saved event interface indicates that the corresponding method is called, and each pointer in the array points to a customer.

INT nConnections = m_vec.getsize (); // Traversing the array said above, takes out the pointer and calls the event response function for (nConnectionIndex = 0; nConnectionIndex lock ); Ccomptr.get (nConnectionIndex); Pt-> unlock (); // strong to iDispatch pointer type // Here more, in general, event callback interface is defined // is DISPINTERFACE (Pure Dispatch Interface), not // is the IDispatch interface (dual interface), which is for the most widely // language compatibility, such as the scripting language only implements DISPINTERFACE // without implementing VTBL. ATL is also implemented by Dispinterface, // However, if only C support can use the VTBL type interface (from // iUnknown inherited interface), but the code will write it own, but // This is simple, because C It is very uncomfortable to use the distribution interface. // Since it is a Dispinterface interface, you can only call the interface function with the Invoke.

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

New Post(0)