我正在尝试将 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);
}
我收到此消息:“在 ... in ... 0xC015000F 处出现未处理的异常:被停用的激活上下文不是最近激活的。”
顺便说一句,这条消息不会在我的 AfxMessageBox 中弹出。它似乎与变体类型有关,因为如果我不设置它,我不会得到异常。pBuffer 中的数据只是之前从 SAFEARRAY 中拉出的 BYTE 数组。
有人知道我在做什么错吗?
谢谢