Re: How to pass a reference to a CComBSTR



"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.

> 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?

There is some class called CAdapt somewhere in ATL...

HTH
Heinz


.



Relevant Pages

  • Re: How to pass a reference to a CComBSTR
    ... >> This is not passing by reference - you are passing pointers. ... CComBSTR tempCComBSTR); ... Approach B (passing by pointer) ...
    (microsoft.public.vc.atl)
  • 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
    ... 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)
  • 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)