我只是试图将一个C ++项目从Windows XP迁移到Windows 7(让它在win7中运行)。
编译是可以的,但是一旦到达下面的代码,应用程序就会崩溃(代码是一段示例代码,但它有同样的问题)。
void Test(const BSTR& b)
{
_variant_t t;
t.vt = VT_BSTR;
t.bstrVal = b;
}
int main()
{
const BSTR b = L"Test";
Test(b);
}
代码在Windows XP中运行良好,但在Windows 7中会发生堆损坏。
如果我从
更改代码_variant_t t;
t.vt = VT_BSTR;
t.bstrVal = b;
到
_variant_t t(b);
然后它在Windows 7上运行正常。
我的问题,为什么第一段代码无法在Windows 7上运行?