1

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

次のメッセージが表示されます。

ちなみに、このメッセージは私の AfxMessageBox には表示されません。設定しないと例外が発生しないため、バリアント型と関係があるようです。pBuffer 内のデータは、以前に SAFEARRAY から引き出された単なる BYTE 配列です。

誰かが私が間違っていることを知っていますか?

ありがとう

4

1 に答える 1

2

SafeArrayCreateセーフ配列を作成し、pvDataメンバーにメモリを割り当てます。pvDataこの後、メンバーをリセットしないでください。pBufferデータを whatから what にコピーするか、または関数pvDataを使用する必要があります。SafeArrayAccessDataSafeArrayPutElement

于 2010-07-16T20:46:10.007 に答える