【发布时间】:2010-07-17 04:54:43
【问题描述】:
我正在尝试将 BYTES 数组中的一些数据包装到一个 VARIANT 中,但我似乎无法释放数据:
当我运行这段代码时...
SAFEARRAY * NewSArray;
SAFEARRAYBOUND aDim[1]; // a one dimensional array
aDim[0].lLbound = 0; //Sets the index to start from 0
//Sets the number of elements (bytes) that will go into the SAFEARRAY
aDim[0].cElements = pBuffer->GetSize();
NewSArray = SafeArrayCreate(VT_UI1, 1, aDim); // create a 1D SafeArray of BYTES
//Put the data from the man view into the SAFEARRAY
NewSArray->pvData = pBuffer->GetBuffer();
//FP Spread expects the spreadsheet data in the form of a VARIANT so we must pack the data from the SAFEARRAY into a
//VARIANT
VARIANT SpreadsheetBuffer;
VariantInit(&SpreadsheetBuffer);
SpreadsheetBuffer.vt= VT_ARRAY | VT_UI1; // set type to an array of bytes
SpreadsheetBuffer.parray= NewSArray;
try
{
VariantClear(&SpreadsheetBuffer);
}
catch (char *str)
{
AfxMessageBox(str);
}
我收到这条消息: “在 ... 0xC015000F 中的未处理异常:被停用的激活上下文不是最近激活的。”
顺便说一句,这条消息不会在我的 AfxMessageBox 中弹出。它似乎与变体类型有关,因为如果我不设置它,我不会得到异常。 pBuffer 中的数据只是之前从 SAFEARRAY 中拉出的 BYTE 数组。
有人知道我做错了什么吗?
谢谢
【问题讨论】:
-
异常与你的代码sn-p完全无关。使调试器在未处理的异常上停止,并在您的问题中发布调用堆栈窗口内容。确保您已启用 Microsoft 符号服务器。
标签: c++ visual-c++ memory-leaks msdn variant