我试图将字节数组中的一些数据打包成一个变体,但似乎无法释放数据:
当我运行这个代码时。。。
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中取出的字节数组。
谢谢