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. BSTR*

BSTR*

Scheduled Pinned Locked Moved C / C++ / MFC
c++com
4 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
    Manikandan
    wrote on last edited by
    #1

    I got to use an activeX control in my VC++ project. When I import the control its wrapper class had a function as below, void CVTSID::Connect(BSTR* RemHost, long* RemPort) { static BYTE parms[] = VTS_PBSTR VTS_PI4; InvokeHelper(0x60030012, DISPATCH_METHOD, VT_EMPTY, NULL, parms, RemHost, RemPort); } I tried to pass the parameters as below, CString str = "192.168.1.155"; BSTR host = str.AllocSysString(); long port = 3246; m_dvt.Connect(&host,&port); The function fails! How I should pass the parameter:confused:

    J 1 Reply Last reply
    0
    • M Manikandan

      I got to use an activeX control in my VC++ project. When I import the control its wrapper class had a function as below, void CVTSID::Connect(BSTR* RemHost, long* RemPort) { static BYTE parms[] = VTS_PBSTR VTS_PI4; InvokeHelper(0x60030012, DISPATCH_METHOD, VT_EMPTY, NULL, parms, RemHost, RemPort); } I tried to pass the parameters as below, CString str = "192.168.1.155"; BSTR host = str.AllocSysString(); long port = 3246; m_dvt.Connect(&host,&port); The function fails! How I should pass the parameter:confused:

      J Offline
      J Offline
      James R Twine
      wrote on last edited by
      #2

      _CString str = "192.168.1.155"; BSTR host = str.AllocSysString(); long port = 3246; m_dvt.Connect(&host,&port);_    First, you are going a really long way just to create a BSTR, you can save yourself one allocation: CComBSTR bstrHost( "192.168.1.155" ); long port = 3246; m_dvt.Connect(&bstrHost,&port);    Second, what error is being returned?  It looks like you are calling the method correctly, was the object created correctly?    Third, when you have to pass pointers to a COM method, it is often because you are going to get something back from the method via those pointers.  COM rules state that if you pass a BSTR pointer, you own whatever BSTR comes back via that pointer, and you transfer ownership of the BSTR you sent, if any.  CComBSTR will automatically deallocate the BSTR (either the one it created, or the one you get back) when its destructor fires.    Peace! -=- James


      If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
      Tip for new SUV drivers: Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
      DeleteFXPFiles & CheckFavorites (Please rate this post!)

      M 1 Reply Last reply
      0
      • J James R Twine

        _CString str = "192.168.1.155"; BSTR host = str.AllocSysString(); long port = 3246; m_dvt.Connect(&host,&port);_    First, you are going a really long way just to create a BSTR, you can save yourself one allocation: CComBSTR bstrHost( "192.168.1.155" ); long port = 3246; m_dvt.Connect(&bstrHost,&port);    Second, what error is being returned?  It looks like you are calling the method correctly, was the object created correctly?    Third, when you have to pass pointers to a COM method, it is often because you are going to get something back from the method via those pointers.  COM rules state that if you pass a BSTR pointer, you own whatever BSTR comes back via that pointer, and you transfer ownership of the BSTR you sent, if any.  CComBSTR will automatically deallocate the BSTR (either the one it created, or the one you get back) when its destructor fires.    Peace! -=- James


        If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
        Tip for new SUV drivers: Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
        DeleteFXPFiles & CheckFavorites (Please rate this post!)

        M Offline
        M Offline
        Manikandan
        wrote on last edited by
        #3

        I receive two errors, 1."Run-time error'9': Subscript out of range" from activeX control itself. 2."Application-defined or object-defined error" thrown by the application.

        M 1 Reply Last reply
        0
        • M Manikandan

          I receive two errors, 1."Run-time error'9': Subscript out of range" from activeX control itself. 2."Application-defined or object-defined error" thrown by the application.

          M Offline
          M Offline
          Manikandan
          wrote on last edited by
          #4

          I came to know the problem is within the activeX control itself. I download the latest control and its working fine without errors. Thank you James.

          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