how to deal with SafeArrayDestroy error?
-
IHTMLDocument2 *document; // Declared earlier in my code HRESULT hr = GetHtmlDocument()->QueryInterface(IID_IHTMLDocument2,(void**) &document); if (!SUCCEEDED(hr)) { return; } HRESULT hresult = S_OK; VARIANT *param; SAFEARRAY *sfArray; BSTR bstr = SysAllocString(OLESTR("hjgjhgjghjhgjhgjhg
")); sfArray = SafeArrayCreateVector(VT_VARIANT, 0, 2); // Creates a new one-dimensional array if (sfArray == NULL || document == NULL) { goto cleanup; } hresult = SafeArrayAccessData(sfArray,(LPVOID*) & param);//获取数组元素 param[0].vt = VT_BSTR; param[0].bstrVal = bstr; param[1].vt = VT_R8; param[1].dblVal = 3.4567; hresult = SafeArrayUnaccessData(sfArray); hresult = document->writeln(sfArray); cleanup: SysFreeString(bstr); if (sfArray != NULL) { SafeArrayDestroy(sfArray); } when i debug , in SafeArrayDestroy(sfArray),an error arises : HEAP[Book.exe]: Invalid Address specified to RtlSizeHeap( 00140000, 02CF0358 ),and there is a messagebox: user breakpoint called from code at ox7c921230. how can i dispose of it? thanks.
-
IHTMLDocument2 *document; // Declared earlier in my code HRESULT hr = GetHtmlDocument()->QueryInterface(IID_IHTMLDocument2,(void**) &document); if (!SUCCEEDED(hr)) { return; } HRESULT hresult = S_OK; VARIANT *param; SAFEARRAY *sfArray; BSTR bstr = SysAllocString(OLESTR("hjgjhgjghjhgjhgjhg
")); sfArray = SafeArrayCreateVector(VT_VARIANT, 0, 2); // Creates a new one-dimensional array if (sfArray == NULL || document == NULL) { goto cleanup; } hresult = SafeArrayAccessData(sfArray,(LPVOID*) & param);//获取数组元素 param[0].vt = VT_BSTR; param[0].bstrVal = bstr; param[1].vt = VT_R8; param[1].dblVal = 3.4567; hresult = SafeArrayUnaccessData(sfArray); hresult = document->writeln(sfArray); cleanup: SysFreeString(bstr); if (sfArray != NULL) { SafeArrayDestroy(sfArray); } when i debug , in SafeArrayDestroy(sfArray),an error arises : HEAP[Book.exe]: Invalid Address specified to RtlSizeHeap( 00140000, 02CF0358 ),and there is a messagebox: user breakpoint called from code at ox7c921230. how can i dispose of it? thanks.
liuyue wrote: SysFreeString(bstr); if (sfArray != NULL) { SafeArrayDestroy(sfArray); From the SafeArrayDestroy documentation:
"Remarks Safe arrays of variant will have VariantClear called on each member [...]."
I think SafeArrayDestroy is calling VariantClear on the first element of the array, which in turn will call SysFreeString on the BSTR you already released. Try not calling SysFreeString before SafeArrayDestroy and see if the error persists. -- jlr http://jlamas.blogspot.com/[^]
-
liuyue wrote: SysFreeString(bstr); if (sfArray != NULL) { SafeArrayDestroy(sfArray); From the SafeArrayDestroy documentation:
"Remarks Safe arrays of variant will have VariantClear called on each member [...]."
I think SafeArrayDestroy is calling VariantClear on the first element of the array, which in turn will call SysFreeString on the BSTR you already released. Try not calling SysFreeString before SafeArrayDestroy and see if the error persists. -- jlr http://jlamas.blogspot.com/[^]
i call SysFreeString(bstr) for bstr , the param[0] is equal to bstr , and has nothing to bstr . i release bstr , but param[0] still exist. what's more, when i make param[1].vt = VT_BSTR; param[1].bstrVal = bstr;, the problem disappears. so i think the problem has nothing with SysFreeString(bstr).