SafeArrayDestroy() 
Author Message
 SafeArrayDestroy()

STDMETHODIMP CCoWrapper::MyFun(VARIANT *vVar, long int *lRet)
{
    SAFEARRAY *pSA;      //pointer to SAFEARRAY in vVar

    //check vVar type
    if ((vVar->vt != (VT_BYREF|VT_ARRAY|VT_UI1))
        && (vVar->vt != (VT_BYREF|VT_ARRAY|VT_UI2)) {
        SafeArrayDestroy(pSA);
        *lRet= -1;
        Error("Array is an invalid data type.");
        return E_FAIL;
    }

    //get the the array part of vVar
    pSA = *vVar->pparray;

    if (SafeArrayGetDim(pSA) != 2) {
        SafeArrayDestroy(pSA);
        *lRet= -2;
        Error("Array must have 2 dimensions.");
        return E_FAIL;
    }

    //working code omitted

    SafeArrayDestroy(pSA);

    *lRet= 0;
    return S_OK;

Quote:
}

question: since the safearray is part of the variant that's passed in, do i
need the calls to SafeArrayDestroy in MyFun?  intuition tells me that since
i create the safearray in MyFun then MyFun is responsible for destroying it.
however, it's derived from an external variable.


Sun, 23 May 2004 22:53:38 GMT  
 SafeArrayDestroy()
No, you should not destroy an array that is passed to you in an [in]
parameter (I assume vVar is an [in] parameter). And what makes you think you
create an array? I don't see any SafeArrayCreate call in your code.
--
With best wishes,
    Igor Tandetnik

"For every complex problem, there is a solution that is simple, neat, and
wrong." H.L. Mencken


Quote:
> STDMETHODIMP CCoWrapper::MyFun(VARIANT *vVar, long int *lRet)
> {
>     SAFEARRAY *pSA;      //pointer to SAFEARRAY in vVar

>     //check vVar type
>     if ((vVar->vt != (VT_BYREF|VT_ARRAY|VT_UI1))
>         && (vVar->vt != (VT_BYREF|VT_ARRAY|VT_UI2)) {
>         SafeArrayDestroy(pSA);
>         *lRet= -1;
>         Error("Array is an invalid data type.");
>         return E_FAIL;
>     }

>     //get the the array part of vVar
>     pSA = *vVar->pparray;

>     if (SafeArrayGetDim(pSA) != 2) {
>         SafeArrayDestroy(pSA);
>         *lRet= -2;
>         Error("Array must have 2 dimensions.");
>         return E_FAIL;
>     }

>     //working code omitted

>     SafeArrayDestroy(pSA);

>     *lRet= 0;
>     return S_OK;
> }

> question: since the safearray is part of the variant that's passed in, do
i
> need the calls to SafeArrayDestroy in MyFun?  intuition tells me that
since
> i create the safearray in MyFun then MyFun is responsible for destroying
it.
> however, it's derived from an external variable.



Mon, 24 May 2004 00:21:04 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. SafeArrayDestroy vs VariantClear?

2. Does SafeArrayDestroy free BSTRs in UDTs

3. Are allocated BSTR freed by SafeArrayDestroy?

 

 
Powered by phpBB® Forum Software