Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. IDispatch to class object

IDispatch to class object

Scheduled Pinned Locked Moved C / C++ / MFC
c++comtestingtoolshelp
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Monark
    wrote on last edited by
    #1

    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

    M 1 Reply Last reply
    0
    • M Monark

      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

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #2

      If 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:

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups