The safe way is to:
BSTR temp = 0;
HRESULT hr = get_Path(&temp);
// TODO: handle errors here
m_bstrNewPath.Attach(temp);
The reason is that get_Path allocates the string and needs to return you a pointer, so the parameter uses double indirection of (chartype) **. _bstr_t, for various reasons, cannot safely wrap this operation. There are a few circumstances where you can avoid the temporary (but you have to know exactly when - and when not). So rather play it safe and use above construct. There is no performance hit involved. in get_Path, path is an [out] only parameter (i.e. the original valeu is ignored). If you have a method with an [in/out] parameter, use:
_bstr_t path = ...; // from whereever
BSTR temp = path.Detach();
HRESULT hr = comObject->ModifyPath(&temp);
path.Attach(temp);
if (FAILED(hr))
{
// handle error here
}
note the different order of attaching vs. error handling.
We are a big screwed up dysfunctional psychotic happy family - some more screwed up, others more happy, but everybody's psychotic joint venture definition of CP
My first real C# project | Linkify!| FoldWithUs! | sighist