Discussion:
how to convert _variant_t to VARIANT*?
(too old to reply)
BruceWho
2006-10-12 05:34:45 UTC
Permalink
my application needs to use a COM component, one of the method uses a
VARIANT* data type like this:

void func(VARIANT* longVar);

and I handle VARIANT variables by _variant_t:

_variant_t var(100);

and now I need to pass var to func, and it doesnot work like this:

func(&var);

so could anybody figure me out how to convert this _variant_t to
VARIANT*?
Egbert Nierop (MVP for IIS)
2006-10-12 12:30:35 UTC
Permalink
Post by BruceWho
my application needs to use a COM component, one of the method uses a
void func(VARIANT* longVar);
_variant_t var(100);
func(&var);
so could anybody figure me out how to convert this _variant_t to
VARIANT*?
Hi Bruce,


This depends. In your case, I suspect that longVar is a *return* value?

If so

*longVar = var.Detach();
should be correct.

If *longVar is in/out you should attach first, and then detach.,

But if the variable is -really- a longVar, you don't need to worry about
memory leaks.

longVar->vt = VT_I4;
longVar->intVal = var.intVal;

should do the trick as well!
Brian Muth
2006-10-12 16:18:05 UTC
Permalink
Post by BruceWho
my application needs to use a COM component, one of the method uses a
void func(VARIANT* longVar);
_variant_t var(100);
func(&var);
But it does. The conversion is implied.

Brian
BruceWho
2006-10-13 00:22:44 UTC
Permalink
Yes, it indeed does. I made a mistake somewhere else.

thanks for your replies.
Post by Brian Muth
Post by BruceWho
my application needs to use a COM component, one of the method uses a
void func(VARIANT* longVar);
_variant_t var(100);
func(&var);
But it does. The conversion is implied.
Brian
Alexander Nickolov
2006-10-12 20:54:43 UTC
Permalink
Is this the exact method definition from the IDL file? This implies
a pure dispinterface, e.g. you need to call via IDispatch::Invoke.
--
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD
email: ***@mvps.org
MVP VC FAQ: http://www.mvps.org/vcfaq
=====================================
Post by BruceWho
my application needs to use a COM component, one of the method uses a
void func(VARIANT* longVar);
_variant_t var(100);
func(&var);
so could anybody figure me out how to convert this _variant_t to
VARIANT*?
Loading...