is there any problem the way i use ccomsafearray?
i have a project written in vc2005(activex)
there is an interface method like this
HRESULT getChildren([in] VARIANT vParent, [out, retval]VARIANT
*pvChildren);
the implementation code something like this:
CMyImpl::getChildren(VARIANT vParent, VARIANT *pvChildren)
{
CComSafeArray<VARIANT> arrChildren;
CComPtr<IMyElementInterface> spElem;
//loop:
.... //get element interface pointer;
arrChildren.Add(CComVariant(spElem));
//end
CComVariant vt(arrChildren);
vt.Detach(pvChildren);
return S_OK;
}
there is a wierd problem :
i could run the program in IDE (press F5),but if i double click it in
explorer to run it, it alerts me an error.
which locates in
microsoft visual studio 8\vc\atlmfc\include\atlcomcli.h
line 1926:
Expression:(___atl_condVal
here is the error location:
CComVariant(__in_opt const SAFEARRAY *pSrc)
{
LPSAFEARRAY pCopy;
if (pSrc != NULL)
{
HRESULT hRes = ::SafeArrayCopy((LPSAFEARRAY)pSrc, &pCopy);
if (SUCCEEDED(hRes) && pCopy != NULL)
{
::ATL::AtlSafeArrayGetActualVartype((LPSAFEARRAY)pSrc,
&vt);
vt |= VT_ARRAY;
parray = pCopy;
}
else
{
vt = VT_ERROR;
scode = hRes;
#ifndef _ATL_NO_VARIANT_THROW
ATLENSURE_THROW(FALSE, E_OUTOFMEMORY); ////////////here
#endif
}
}
i don't know why this happens