我需要在 VariantChangeType 之后调用 VariantClear
我有以下 C++ 代码。我需要释放“varDest”变量吗?
VARIANT val;
if(SUCCEEDED(classObj->Get(pwPropName, 0, &val, NULL, 0))) //WMI property retrieval
{
//Then at some point
VARIANT varDest;
varDest.vt = VT_EMPTY;
if(SUCCEEDED(::VariantChangeType(&varDest,
const_cast<VARIANT *>(&val), 0, VT_BSTR)))
{
//Do I need to call the following?
VariantClear(&varDest);
}
VariantClear(&val);
}
I have the following code in C++. Do I need to free 'varDest' variable?
VARIANT val;
if(SUCCEEDED(classObj->Get(pwPropName, 0, &val, NULL, 0))) //WMI property retrieval
{
//Then at some point
VARIANT varDest;
varDest.vt = VT_EMPTY;
if(SUCCEEDED(::VariantChangeType(&varDest,
const_cast<VARIANT *>(&val), 0, VT_BSTR)))
{
//Do I need to call the following?
VariantClear(&varDest);
}
VariantClear(&val);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,您必须调用
VariantClear
。如果成功,VariantChangeType
方法实际上会将源的副本强制到目标中。目的地中的此副本现在是独立跟踪的,并且必须独立清除。Yes you must call
VariantClear
. TheVariantChangeType
method if successful will essentially coerce a copy of the source into the destination. This copy in the destination is now independently tracked and must be independently cleared.