How to pass a reference to a CComBSTR



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 call is occuring within the same component and not across COM boundies
etc. Just one function within my ATL object needing to call another
function.

However when I compile I get:
test.cpp(235) : error C2664: 'myfunction' : cannot convert parameter 1 from
'unsigned short ** ' to 'class ATL::CComBSTR *'

>From searching I've read that you cannot pass a CComBSTR by reference
because it overloads the & operator.

I am using Visual Studio 6.0 and that is my only option. What is the MOST
EFFICIENT way I can handle this need? I read something from Microsoft about
using a "container" if you need to pass a CComBSTR by reference, but I'm not
sure what they mean. Can someone provide a quick example of that?

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.

Thanks in advance for any help you can provide.

Steve


.



Relevant Pages

  • 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)
  • 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: How to pass a reference to a CComBSTR
    ... function B by REFERENCE, so that function B can update this variable with a new string it calculates. ... and myfunction looks like this: ... Some wise guy at MS thought it to be a good idea to overload operator& to make a CComBSTR easyly mix with plain BSTR. ...
    (microsoft.public.vc.atl)
  • Re: BSTR CComBSTR Issues Visual Basic 6
    ... I thought that the CComBSTR type might be the answer to my problem. ... string to the method. ... >> Private Sub X ... >> HRESULT FinalConstruct() ...
    (microsoft.public.vc.atl)

Loading