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. COM works in VB but not VC.

COM works in VB but not VC.

Scheduled Pinned Locked Moved C / C++ / MFC
comhelpquestionlearningworkspace
2 Posts 2 Posters 6 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.
  • U Offline
    U Offline
    User 3512
    wrote on last edited by
    #1

    Here is a VB test app. It is not very complex or clever, but it works. Dim WithEvents mcs As MCSClient mcs.Initialize "MyString" where MCSClient is a com object added to the VB environment by adding a reference. Not a component, but a reference. I would like an equivalent VC app to this VB app. So I wrote some code like this. I use the Wizard to generate a wrapper class over the same dll the VB referenced and in my header I define a variable of the wrapper type as such. IMCSClient m_IMCSClient; Then in my code I successfully create the dispatch like so. if(((*(COleDispatchDriver*)(&m_IMCSClient))).m_lpDispatch==NULL){ if (!(m_IMCSClient.CreateDispatch("4E51E425-021E-11D2-B759-0020AFF84106", &oe))) { } } I can also use the progid in creating the dispatch, either way works. Here comes the problem, I want to perform the Initialze method. (Just like VB did.) m_IMCSClient.Initialize("MyString); When, this code excutes it will throw the following exception. DISP_E_MEMBERNOTFOUND I am not sure what it means. Is anyone familar enough with VB to know what WithEvents means? Can anyone suggest a different course of action.

    A 1 Reply Last reply
    0
    • U User 3512

      Here is a VB test app. It is not very complex or clever, but it works. Dim WithEvents mcs As MCSClient mcs.Initialize "MyString" where MCSClient is a com object added to the VB environment by adding a reference. Not a component, but a reference. I would like an equivalent VC app to this VB app. So I wrote some code like this. I use the Wizard to generate a wrapper class over the same dll the VB referenced and in my header I define a variable of the wrapper type as such. IMCSClient m_IMCSClient; Then in my code I successfully create the dispatch like so. if(((*(COleDispatchDriver*)(&m_IMCSClient))).m_lpDispatch==NULL){ if (!(m_IMCSClient.CreateDispatch("4E51E425-021E-11D2-B759-0020AFF84106", &oe))) { } } I can also use the progid in creating the dispatch, either way works. Here comes the problem, I want to perform the Initialze method. (Just like VB did.) m_IMCSClient.Initialize("MyString); When, this code excutes it will throw the following exception. DISP_E_MEMBERNOTFOUND I am not sure what it means. Is anyone familar enough with VB to know what WithEvents means? Can anyone suggest a different course of action.

      A Offline
      A Offline
      Alex Gorev
      wrote on last edited by
      #2

      Hi ! When you create the object in VB using "WithEvens" it means that the object can fire events. See VB documentation for more details. You are trying to use the IDispatch interface but probably the object you are using supports dual interfaces. It's much easier from C++ and much faster. You can use the #import directive with the name of the DLL file you are using to import the type library information and the use the QueryInterface function. Regards, Alex Gorev, Dundas Software. ================== The original message was: Here is a VB test app. It is not very complex or clever, but it works.

      Dim WithEvents mcs As MCSClient
      mcs.Initialize "MyString"

      where MCSClient is a com object added to the VB environment by adding a reference. Not a component, but a reference.

      I would like an equivalent VC app to this VB app. So I wrote some code like this.

      I use the Wizard to generate a wrapper class over the same dll the VB referenced and in my header I define a variable of the wrapper type as such.

      IMCSClient m_IMCSClient;

      Then in my code I successfully create the dispatch like so.

      if(((*(COleDispatchDriver*)(&m_IMCSClient))).m_lpDispatch==NULL){
      if (!(m_IMCSClient.CreateDispatch("4E51E425-021E-11D2-B759-0020AFF84106", &oe))) {
      }
      }

      I can also use the progid in creating the dispatch, either way works.

      Here comes the problem, I want to perform the Initialze method. (Just like VB did.)
      m_IMCSClient.Initialize("MyString);

      When, this code excutes it will throw the following exception.
      DISP_E_MEMBERNOTFOUND

      I am not sure what it means.
      Is anyone familar enough with VB to know what WithEvents means?
      Can anyone suggest a different course of action.

      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