Re: IsObject (VB) in C++
"Robert" <Robert@discussions.microsoft.com> schrieb im Newsbeitrag
news:7A179F01-B471-42C2-B549-343A995A83AF@microsoft.com...
Hi, is there any analog to IsObject (same as IsWindow) in VC++ ???
Usually there is no need for a function like IsObject in C++. Just look at
the type of the variable. If the type is a pointer to an interface,
something derived from IUnknown, (and its value is non-zero), it is (a
pointer to) "an object". You only need such functions for languages where a
single variable can hold values of different types during its lifetime.
Only when you are using variables of type VARIANT (or CComVariant or
_variant_t) or something like boost::any, you have to determine the actual
type at run-time. Then, for VARIANT, CComVariant or _variant_t you can
examine the vt member variable to determine the type. For these rare cases,
you can easyly implement IsObject as
bool IsObject(VARIANT const& v)
{
return v.vt == VT_UNKNOWN || v.vt == VT_DISPATCH;
}
but usually it is much easier to switch on VARIANT::vt instead of using
IsObject, IsNumber, IsString and whatever other functions there are in VB to
determine the type of a variable.
HTH
Heinz