Article ID: 138414 - Last Review: November 21, 2006 - Revision: 3.1 PRB: FromIDispatch Returns NULL for OLE ControlThis article was previously published under Q138414 SYMPTOMS
Calling CCmdTarget::FromIDispatch() inside a member function of a class
derived from COleControl or attempting to call FromIDispatch() passing
an IDispatch pointer belonging to an OLE Control, will always return
NULL.
CAUSE
CCmdTarget::FromIDispatch() does the following test to determine if the
passed IDispatch pointer belongs to a CCmdTarget-derived class or not:
RESOLUTION
It is possible to access the object of the class derived from COleControl
given a valid IDispatch pointer. The object can be accessed from another
control or outside of a control with the aid of a helper control. A helper
control would be necessary because the following formula relies on details
that are internal to a COleControl class. To access the object of the class derived from COleControl successfully, you need to use a formula similar to this one: m_xDispatch is generated by the END_INTERFACE_PART macro as follows: m_nOffset is generated by the INIT_INTERFACE_PART macro as follows: STATUS
This behavior is by design.
MORE INFORMATION
This difference between CCmdTarget and COleControl's implementation of
IDispatch disappears in Visual C++ version 4.0. COleControl uses
COleDispatchImpl in version 4.0 and therefore, FromIDispatch() will work.
APPLIES TO
| Article Translations
|

Back to the top
