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. COM
  4. Returning a dispinterface from VC to VB

Returning a dispinterface from VC to VB

Scheduled Pinned Locked Moved COM
c++helpquestion
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.
  • J Offline
    J Offline
    Jon Taylor
    wrote on last edited by
    #1

    I'm trying to write a function which returns a pointer to itself from my ATL C++ code to a VB application. My ATL object uses dispinterfaces to be compatible with VB. In my IDL, I declare the my function: [id(1)] HRESULT GetComponent ([out, retval] IDispatch *pRetval); I implement the function OK and return a pointer to IDispatch that I've obtained with QueryInterface. Oh, this interface is part of a coclass alled "MyControl". So GetComponent basically returns QueryInterface on "this". (And it works, too:)) I declare the interface as "oleautomation". Now using the Visual Basic object browser, I can see my GetComponent method and it's returning an "object". Now, I can set it OK if I set it as an object: Dim Test as Object Set Test = oControl.GetComponent ' oControl is type MyControl However, if I declare "Test" as type "MyControl", I get a type mismatch: Dim Test as MyControl set Test = oControl.GetComponent ' Causes a type mismatch Help! I just cannot get this to work. Is there something i must mark the IDL with, or is this a Visual Basic issue?:mad: Thanks in advance :) Jon

    V 1 Reply Last reply
    0
    • J Jon Taylor

      I'm trying to write a function which returns a pointer to itself from my ATL C++ code to a VB application. My ATL object uses dispinterfaces to be compatible with VB. In my IDL, I declare the my function: [id(1)] HRESULT GetComponent ([out, retval] IDispatch *pRetval); I implement the function OK and return a pointer to IDispatch that I've obtained with QueryInterface. Oh, this interface is part of a coclass alled "MyControl". So GetComponent basically returns QueryInterface on "this". (And it works, too:)) I declare the interface as "oleautomation". Now using the Visual Basic object browser, I can see my GetComponent method and it's returning an "object". Now, I can set it OK if I set it as an object: Dim Test as Object Set Test = oControl.GetComponent ' oControl is type MyControl However, if I declare "Test" as type "MyControl", I get a type mismatch: Dim Test as MyControl set Test = oControl.GetComponent ' Causes a type mismatch Help! I just cannot get this to work. Is there something i must mark the IDL with, or is this a Visual Basic issue?:mad: Thanks in advance :) Jon

      V Offline
      V Offline
      Vi2
      wrote on last edited by
      #2

      You should specify pointer to interface pointer to return your object. [id(1)] HRESULT GetComponent ([out, retval] IDispatch* *pRetval); Sure to call AddRef() on it before the function's exit. With best wishes, Vita

      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