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. Using ActiveX wrapper class in MFC console

Using ActiveX wrapper class in MFC console

Scheduled Pinned Locked Moved C / C++ / MFC
comhelpquestionc++
3 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.
  • Y Offline
    Y Offline
    yccheok
    wrote on last edited by
    #1

    Previously, I have an ActiveX control which I use it in my MFC GUI program. The wrapper class (inheritanced from CWnd) for the activex control is generated automatically through class wizard. Everything just work fine. Now, I need my application to work in non-gui mode. Hence, no dialog or windows will be created to host the active x control. I just copy the ActiveX wrapper class file, which is generated previously, into my console project. i realize that a runtime error will occur whenever i try to use the active x control. this is because there is no dialog/ or windows to host that activex control. I read an article at http://www.codeproject.com/com/consoleactivex.asp The author shows the way by using COM. However, i am not familiar with COM. I prefer to use back the wizard generated wrapper source code, which is much more easier. may i noe how can i solve this problem? do i need to created a hidden window for it? or is there better way? thanks! cheok

    C 1 Reply Last reply
    0
    • Y yccheok

      Previously, I have an ActiveX control which I use it in my MFC GUI program. The wrapper class (inheritanced from CWnd) for the activex control is generated automatically through class wizard. Everything just work fine. Now, I need my application to work in non-gui mode. Hence, no dialog or windows will be created to host the active x control. I just copy the ActiveX wrapper class file, which is generated previously, into my console project. i realize that a runtime error will occur whenever i try to use the active x control. this is because there is no dialog/ or windows to host that activex control. I read an article at http://www.codeproject.com/com/consoleactivex.asp The author shows the way by using COM. However, i am not familiar with COM. I prefer to use back the wizard generated wrapper source code, which is much more easier. may i noe how can i solve this problem? do i need to created a hidden window for it? or is there better way? thanks! cheok

      C Offline
      C Offline
      Calc20
      wrote on last edited by
      #2

      Use the class wizard to generate a wrapper class, not derived from CWnd, but from COleDispatchDriver. In ClassWizard click Add Class then select From a type libary and select the .tlb file of your control. After you have the wrapper class call CoCreateInstance to create the object, something like: IDispatch* pDisp; CoCreateInstance(clsid, NULL, CLSCTX_INPROC_SERVER, dispid, &pDisp); where clsid is the class id for the object, dispid is the ID of object's IDispatch interface After a successful call of CoCreateInstance use the AttachDispatch method from the wrapper class and then you can call ActiveX methods, like this: CWrapperClass myDisp; myDisp.AttachDispatch(pDisp); myDisp.SomeActiveXMethod(); Remember to call CoInitialize before CoCreateInstance and when you're done using the object call pDisp->Release() in order to decrement the object's reference count and destroy it.

      Y 1 Reply Last reply
      0
      • C Calc20

        Use the class wizard to generate a wrapper class, not derived from CWnd, but from COleDispatchDriver. In ClassWizard click Add Class then select From a type libary and select the .tlb file of your control. After you have the wrapper class call CoCreateInstance to create the object, something like: IDispatch* pDisp; CoCreateInstance(clsid, NULL, CLSCTX_INPROC_SERVER, dispid, &pDisp); where clsid is the class id for the object, dispid is the ID of object's IDispatch interface After a successful call of CoCreateInstance use the AttachDispatch method from the wrapper class and then you can call ActiveX methods, like this: CWrapperClass myDisp; myDisp.AttachDispatch(pDisp); myDisp.SomeActiveXMethod(); Remember to call CoInitialize before CoCreateInstance and when you're done using the object call pDisp->Release() in order to decrement the object's reference count and destroy it.

        Y Offline
        Y Offline
        yccheok
        wrote on last edited by
        #3

        Thanks. Using COleDispatchDriver as parent class really work! I didn't use AttachDispatch since I cann't make it works. Most probably I miss out something. However, by using CreateDispatch just rock :) I assume there is no clean up needed after CreateDispatch from the MSDN example. Thanks for help! cheok

        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