BSTR newID_x = SysAllocString(L"newID");
BSTR newX_x = SysAllocString(L"newX");
functionA(&newID_x);
//Func A does some operation on newID_x, we have that value in newID_x now
functionA(&newX_x);
//After Func A is called for the second time, both newID_x and newX_x become the same
//i.e, both are pointing开发者_JS百科 to same locations and hence values too
My question is that, is it a correct behavior for BSTR
s, do we need to save the newX_x
in some new BSTR
after calling functionA
the first time?
Or is it wrong on part of functionA
that it may be wrongly allocating/de-allocating the passed BSTR
s.
What you describe is "in-out" parameter semantics - the parameter is initialized prior to call, then while in the call it is changed and the change is visible to the caller. It is acceptable, but having such interface is not very convenient. In this case the callee will have to reallocate the BSTR
and then pass ownership to the caller.
精彩评论