VARIANT to std::string

Here’s one way, not necessarily the best. In general, std::string doesn’t
play very well with VARIANT.

#include <comutil.h>
#include <string>

std::string from_variant(VARIANT& vt)
{
_bstr_t bs(vt);
return std::string(static_cast<const char*>(bs));
}

void to_variant(const std::string& str, VARIANT& vt)
{
_bstr_t bs(str.c_str());
reinterpret_cast<_variant_t&>(vt) = bs;
}

 

또한.. VARIANT가 비어 있는지 확인 하는 방법은?

VT_NULL == value.vt || VT_EMPTY == value.vt

이렇게~~