CComVariant bstrTarget;
CComBSTR strSource("test");
// Use CComBSTR::Copy to make a copy
// of the source string.
bstrTarget.bstrVal = strSource.Copy();
If you don't make a copy of the source string, it will wind up being freed twice—once by the
CComVariant's destructor, and once by the original
CComBSTR's destructor.
Avoid Memory Corruption when Assigning a CComBSTR to a CComVariant's bstrVal Member
最新推荐文章于 2022-06-21 14:34:38 发布