Re: How to pass a reference to a CComBSTR



"Heinz Ozwirk" <hozwirk.SPAM@xxxxxxxx> wrote in message news:42ec8069$0$29078$9b4e6d93@xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
"Steve Franks" <please@xxxxxxxxxxxxxxxxx> schrieb im Newsbeitrag news:_t6dnYV4EPK_V3bfRVn-qg@xxxxxxxxxxxxxx
I have a CComBSTR variable in function A. I want to pass this variable to function B by REFERENCE, so that function B can update this variable with a new string it calculates.

I'm passing in my CComBSTR like this:  myfunction(& myCComBSTRvar)
 and myfunction looks like this:
void myfunction(CComBSTR *myCComBSTRvarToUpdate) {}

This is not passing by reference - you are passing pointers. To pass by reference yous should declare myfunction as


   void myfunction(CComBSTR& myModifiableVariable)...

and call it like

   myfunction(myCComBSTRvar);

Some wise guy at MS thought it to be a good idea to overload operator& to make a CComBSTR easyly mix with plain BSTR. But by doing that he made it impossible to get the address of a CComBSTR itself. If you only use CComBSTR as a wrapper for BSTR, you should have a look at _bstr_t.

To my best knowledge, the solution would be using the m_str itself.


.



Relevant Pages

  • Re: How to pass a reference to a CComBSTR
    ... > I'm passing in my CComBSTR like this: myfunction(& myCComBSTRvar) ... This is not passing by reference - you are passing pointers. ...
    (microsoft.public.vc.atl)
  • Re: OO javascript... this doesnt appear to point to the object
    ... aspects of JavaScript OOP (completely missed in 99.9% of relevant ... function myFunction() ... var myFunction= function; ... variable myFunction and then we are assigning a reference of that newly ...
    (comp.lang.javascript)
  • Re: How to pass a reference to a CComBSTR
    ... >>> reference yous should declare myfunction as ... I wouldn't use Detach to assign one CComBSTR to another one. ... If you want speed that badly, you have to use plain BSTR. ... Before you can assign a new string to a BSTR ...
    (microsoft.public.vc.atl)
  • Re: How to pass a reference to a CComBSTR
    ... From searching I've read that you cannot pass a CComBSTR by reference because it overloads the & operator. ... Clearly I could pass my CComBSTR by value and return a string, and then once it gets back I could just set the CComBSTR to the returned string value. ... However this is a very critical piece of the code where performance is critical and this code is called intensively so performance optimization matters the most here. ...
    (microsoft.public.vc.atl)
  • How to pass a reference to a CComBSTR
    ... I'm passing in my CComBSTR like this: ... >From searching I've read that you cannot pass a CComBSTR by reference ... Clearly I could pass my CComBSTR by value and return a string, ... critical and this code is called intensively so performance optimization ...
    (microsoft.public.vc.atl)

Loading