IDispatch to class object
-
Hi All, I am developing a MFC ActiveX Control. In that I have exposed one method to the automation client.This method has four argument. First will be the object of class CMyItem and second will be the object of CMyObj class.
LONG CMyCtrl::ExecuteRequest(IDispatch* myItem,IDispatch* myObj, LPCTSTR str1,LPCTSTR extraInfo) { return 0; }
Now I want to get back the object from IDispatch. i.e.CMyObj m_obj; CMyItem m_item; m_item = myItem ; // first argument IDispatch* myItem myobj = myObj ;// second argument IDispatch* myObj myobj.Dosomething();
But the compiler is giving an error saying that cant convert from IDispatch to class object. Any Idea how can I get cast the object from IDispatch to class Thanks, Micky -
Hi All, I am developing a MFC ActiveX Control. In that I have exposed one method to the automation client.This method has four argument. First will be the object of class CMyItem and second will be the object of CMyObj class.
LONG CMyCtrl::ExecuteRequest(IDispatch* myItem,IDispatch* myObj, LPCTSTR str1,LPCTSTR extraInfo) { return 0; }
Now I want to get back the object from IDispatch. i.e.CMyObj m_obj; CMyItem m_item; m_item = myItem ; // first argument IDispatch* myItem myobj = myObj ;// second argument IDispatch* myObj myobj.Dosomething();
But the compiler is giving an error saying that cant convert from IDispatch to class object. Any Idea how can I get cast the object from IDispatch to class Thanks, MickyIf the objects are derived from IDispatch, you should be able to downcast the passed IDispatch pointers. Note that you can't directly cast a pointer to an object like you've shown.
// assumes using RTTI
CMyObj *m_obj;
CMyItem *m_item;m_item = dynamic_cast<CMyItem *>(myItem) ; // first argument IDispatch* myItem
myobj = dynamic_cast<CMyObj *>(myObj) ;// second argument IDispatch* myObj// make sure m_item/myobj not NULL!!
...myobj->Dosomething();
Mark
Mark Salsbery Microsoft MVP - Visual C++ :java: