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. Making things pretty by returning BSTR's (ATLCOM)

Making things pretty by returning BSTR's (ATLCOM)

Scheduled Pinned Locked Moved COM
learningc++com
6 Posts 6 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.
  • T Offline
    T Offline
    Tim Rymer
    wrote on last edited by
    #1

    We're making an ATL object to be used in ASP or Visual Basic. I want to be able to return a BSTR to make it nice and pretty for my VB partner. Ok ok, we all know that you can say... /////////////// STDMETHODIMP Foo([out,retval] BSTR outstring) /////////////// ..and have it returned in a variable in the Implementation. (duh) But can we get this a function in an object to look like: /////////////// BSTR Foo(BSTR instring); /////////////// or just something with the emphasis on returning a BSTR in the "real" return parameter place. "The Master Wang" doesnt have money to buy a COM or ATL book... and plus I know I'm asking questions from the best! ;) SHABBA!! *Please Contact Me if you have a Donation to give to a poor college student who needs money for a engagement ring for the greatest girl in the world. :-D -~= The (still learning) Master Wang =~-

    N S M L B 5 Replies Last reply
    0
    • T Tim Rymer

      We're making an ATL object to be used in ASP or Visual Basic. I want to be able to return a BSTR to make it nice and pretty for my VB partner. Ok ok, we all know that you can say... /////////////// STDMETHODIMP Foo([out,retval] BSTR outstring) /////////////// ..and have it returned in a variable in the Implementation. (duh) But can we get this a function in an object to look like: /////////////// BSTR Foo(BSTR instring); /////////////// or just something with the emphasis on returning a BSTR in the "real" return parameter place. "The Master Wang" doesnt have money to buy a COM or ATL book... and plus I know I'm asking questions from the best! ;) SHABBA!! *Please Contact Me if you have a Donation to give to a poor college student who needs money for a engagement ring for the greatest girl in the world. :-D -~= The (still learning) Master Wang =~-

      N Offline
      N Offline
      Not Active
      wrote on last edited by
      #2

      If I understand what your asking STDMETHODIMP Foo([out,retval] BSTR return_string, [out]BSTR out_string) would get you BSTR Foo(BSTR instring) BTW, nice sucking up;)

      1 Reply Last reply
      0
      • T Tim Rymer

        We're making an ATL object to be used in ASP or Visual Basic. I want to be able to return a BSTR to make it nice and pretty for my VB partner. Ok ok, we all know that you can say... /////////////// STDMETHODIMP Foo([out,retval] BSTR outstring) /////////////// ..and have it returned in a variable in the Implementation. (duh) But can we get this a function in an object to look like: /////////////// BSTR Foo(BSTR instring); /////////////// or just something with the emphasis on returning a BSTR in the "real" return parameter place. "The Master Wang" doesnt have money to buy a COM or ATL book... and plus I know I'm asking questions from the best! ;) SHABBA!! *Please Contact Me if you have a Donation to give to a poor college student who needs money for a engagement ring for the greatest girl in the world. :-D -~= The (still learning) Master Wang =~-

        S Offline
        S Offline
        Shadi Al Kahwaji
        wrote on last edited by
        #3

        Hi, Actually you can use any data type "Automation Data Types are recomended" to be a return type of any interface's method. But, it's just a recommendation that you use the HRESULT (STDMETHOD macro) as a return type, this return type will give the COM Runtime Environment the ability to return error codes when your component cannot be accessed for any reason. If you don't provide HRESULT as a return type, the COM Runtime Environment cannot return error codes for you. "If You Know That Your Component Will Live With Its Client On The Same Machine, You Can Ignore HRESULT" Regards, ShadiK.

        1 Reply Last reply
        0
        • T Tim Rymer

          We're making an ATL object to be used in ASP or Visual Basic. I want to be able to return a BSTR to make it nice and pretty for my VB partner. Ok ok, we all know that you can say... /////////////// STDMETHODIMP Foo([out,retval] BSTR outstring) /////////////// ..and have it returned in a variable in the Implementation. (duh) But can we get this a function in an object to look like: /////////////// BSTR Foo(BSTR instring); /////////////// or just something with the emphasis on returning a BSTR in the "real" return parameter place. "The Master Wang" doesnt have money to buy a COM or ATL book... and plus I know I'm asking questions from the best! ;) SHABBA!! *Please Contact Me if you have a Donation to give to a poor college student who needs money for a engagement ring for the greatest girl in the world. :-D -~= The (still learning) Master Wang =~-

          M Offline
          M Offline
          Michael P Butler
          wrote on last edited by
          #4

          >..and have it returned in a variable in the Implementation. (duh) >But can we get this a function in an object to look like: >/////////////// >BSTR Foo(BSTR instring); >/////////////// No, COM interfaces can't return a value like you suggest. The correct (and only way) is as you described,

          STDMETHODIMP Foo([out,retval] BSTR* outstring)

          Your VB code would then look like, Dim sTemp sTemp = Object.Foo Hope this helps, Michael :-)

          1 Reply Last reply
          0
          • T Tim Rymer

            We're making an ATL object to be used in ASP or Visual Basic. I want to be able to return a BSTR to make it nice and pretty for my VB partner. Ok ok, we all know that you can say... /////////////// STDMETHODIMP Foo([out,retval] BSTR outstring) /////////////// ..and have it returned in a variable in the Implementation. (duh) But can we get this a function in an object to look like: /////////////// BSTR Foo(BSTR instring); /////////////// or just something with the emphasis on returning a BSTR in the "real" return parameter place. "The Master Wang" doesnt have money to buy a COM or ATL book... and plus I know I'm asking questions from the best! ;) SHABBA!! *Please Contact Me if you have a Donation to give to a poor college student who needs money for a engagement ring for the greatest girl in the world. :-D -~= The (still learning) Master Wang =~-

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            The solution is simple. In your source file (.cpp) change your function header to this: STDMETHODIMP_(BSTR) YourClass::Foo(BSTR instring) and do the same for your (.h) file. You need to change the entry in the IDL file as well,like the following: BSTR Foo(BSTR instring);:) :) Rookie Programmer

            1 Reply Last reply
            0
            • T Tim Rymer

              We're making an ATL object to be used in ASP or Visual Basic. I want to be able to return a BSTR to make it nice and pretty for my VB partner. Ok ok, we all know that you can say... /////////////// STDMETHODIMP Foo([out,retval] BSTR outstring) /////////////// ..and have it returned in a variable in the Implementation. (duh) But can we get this a function in an object to look like: /////////////// BSTR Foo(BSTR instring); /////////////// or just something with the emphasis on returning a BSTR in the "real" return parameter place. "The Master Wang" doesnt have money to buy a COM or ATL book... and plus I know I'm asking questions from the best! ;) SHABBA!! *Please Contact Me if you have a Donation to give to a poor college student who needs money for a engagement ring for the greatest girl in the world. :-D -~= The (still learning) Master Wang =~-

              B Offline
              B Offline
              Bill Wilson
              wrote on last edited by
              #6

              STDMETHODIMP Foo([in]BSTR in_string, [out,retval] BSTR *return_string ) would get you String Foo(String instring) in VB or ASP, In C++ it is HRESULT = YADA.Invoke(dispID, params, vResult,...) Your out_string ends up in the Variant vResult as type vt = VT_BSTR. Use of the retval modifier causes the result to be placed in vResult. Notice the * in BSTR *return_string. Hope this helps, Bill

              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