Should there be a difference between an empty BSTR and a NULL BSTR?

后端 未结 2 1335
你的背包
你的背包 2020-12-15 11:04

When maintaining a COM interface should an empty BSTR be treated the same way as NULL? In other words should these two function calls

2条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-15 11:54

    The easiest way to handle this dilemma is to use CComBSTR and check for .Length() to be zero. That works for both empty and NULL values.

    However, keep in mind, empty BSTR must be released or there will be a memory leak. I saw some of those recently in other's code. Quite hard to find, if you are not looking carefully.

提交回复
热议问题