如果未事先调用variantInit,变体将崩溃软件崩溃?

发布于 01-18 22:30 字数 611 浏览 4 评论 0原文

我有一个例外,我不能轻易复制,但是我非常怀疑它发生在variantClear()中。

我的函数可以定义一个变体,然后将其传递给另一个变体,而无需首先调用variantinit()。然后调用函数在此变体上调用variantClear(),这可能是例外的来源。

void Func1()
{
  VARIANT vData;
  //VariantInit(&vData); // no variant clear was done. Will adding this line stop the crash below?
  Func2(vData);
}

void Func2(VARIANT& vData)
{
  // some code here
  VariantClear(&vData); <-- this line crashes, why??
  // some code here
}

谁能解释为什么variantClear()可能会引发异常?在func1()中呼叫variantinit()停止此异常发生吗?

I have an exception that I cannot easily replicate, but I have a very strong suspicion that it happens during VariantClear().

I have a function that defines a variant and then passes it off to another variant without calling VariantInit() on it first. The called function then calls VariantClear() on this variant, which is the likely source of the exception.

void Func1()
{
  VARIANT vData;
  //VariantInit(&vData); // no variant clear was done. Will adding this line stop the crash below?
  Func2(vData);
}

void Func2(VARIANT& vData)
{
  // some code here
  VariantClear(&vData); <-- this line crashes, why??
  // some code here
}

Can anyone explain why VariantClear() could be throwing an exception? Will calling VariantInit() in Func1() stop this exception from happening?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一生独一2025-01-25 22:30:31

VariantClear 检查 VARIANT 的前 16 位以查找变体类型。

根据类型的不同,VariantClear 可能会调用 CoTaskMemFree 或将变体视为其调用 Release 的 COM 指针。如果类型无效,您可能会崩溃或释放一些不相关的内存。

如果类型是 VT_EMPTY、VT_NULL 或数字类型,它只会将所有字段设置为零。

如果您不初始化 VARIANT,则类型未定义,它可能是上一操作留在内存中的任何值。因此,您必须首先在 VARIANT 上调用 VariantInit

VariantClear checks the first 16 bits of the VARIANT to find the variant type.

Depending on the type, VariantClear might call CoTaskMemFree or treat the variant as a COM pointer it calls Release on. If the type is invalid you might crash or free some unrelated memory.

If the type is VT_EMPTY, VT_NULL or a number type it just sets all fields to zero.

If you don't initialize the VARIANT, the type is undefined, it could be any value left in memory from a previous operation. Therefore you must call VariantInit first on the VARIANT.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文