开发者

VariantClear() throws an exception when called on A VARIANT containing a SAFEARRAY

I am trying to wrap up some data from an array of BYTES into a VARIANT but I can't seem to free the data:

When I run this code...

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);
}

I get this message: "Unhandeled exception at ... in ... 0xC015000F: The activation context being deactivated is not the most recently activated one."

This message dosen't pop up in my AfxMessageBox by the way. It seems to have something to do with the variant type because if I don't set it I don't get the exception. The data in pBuffer is just a BYTE array that was previously pulled out of a SAFEARRAY.

anyone know what I'm doing wrong?

thanks


SafeArrayCreate creates a safe-array and allocates memory for the pvData member. You should not reset the pvData member after this. You should copy your data from pBuffer into what pvData points to, or use the SafeArrayAccessData or SafeArrayPutElement functions.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜