关于VariantClear函数释放SAFEARRAY所占内存失败的问题?
有段代码如下:
VARIANT var;
HRESULT hr;
SAFEARRAY* psa = NULL;
BYTE* pByte = NULL;
::VariantInit(&var);
psa = ::SafeArrayCreateVector(VT_UI1, 0, 1024*1024*3);
::SafeArrayAccessData(psa, (void**) &pByte);
for (int i = 0; i < 1024*1024*3; i++)
{
*(pByte + i) = 1;
}
::SafeArrayUnaccessData(psa);
var.vt = VT_ARRAY;
var.parray = psa;
hr = ::VariantClear(&var);
在调用VariantClear函数后,hr的值为0x80020008,"Bad Variable Type" for SAFEARRAY,同时内存显示没有释放上面分配的3M(1024*1024*3)内存.
MSDN上关于VariantClear函数有段说明是"The function clears a VARIANTARG by setting the vt field to VT_EMPTY. The current contents of the VARIANTARG are released first. If the vt field is VT_BSTR, the string is freed. If the vt field is VT_DISPATCH, the object is released. If the vt field has the VT_ARRAY bit set, the array is freed."
有谁知道为什么VariantClear函数失败?