daiyue
daiyue

Reputation: 7458

Check if a BSTR is empty

I have a variant that contains a BSTR, but sometimes the BSTR is "" (empty), so how to avoid this? I have tried something like:

variant.bstrVal != NULL

But it didn't work.

Upvotes: 6

Views: 10359

Answers (2)

Native.Nilesh
Native.Nilesh

Reputation: 1

You can test the vt member of VARIANT for VT_NULL or VT_EMPTY

if (variant.vt != VT_NULL)
{
   ...
}

Upvotes: -2

Sergey Sirotkin
Sergey Sirotkin

Reputation: 1677

Use SysStringLen:

if (SysStringLen(variant.bstrVal) == 0)
{ ... }

Upvotes: 23

Related Questions