Question about SAFEARRAYS and deleteing them 
Author Message
 Question about SAFEARRAYS and deleteing them

I'm reading a COM+/ATL book (Andrew Troelsen-- very good), and in the
section on SAFEARRAYS he has some code like so:

STDMETHOD CCoSafeArray::UseThisSafeArrayOfStrings(VARIANT strings)
{
.
.
.
    SAFEARRAY *pSA = strings.parray;
.
.
.
.
    SafeArrayUnaccessData(pSA);
    SafeArrayDestroy(pSA);  //what the...?

Quote:
}

My question is: why am I destroying the SAFEARRAY?  Up at the top of the
function, I didn't allocate any memory for it-- I'm just pointing to the
incoming parameter's copy of the array.  Maybe I'm mistaken, and assigning a
SAFEARRAY pointer to another array somehow allocates memory in the
background?  Or do you think this is a typo on the author's part?  Thanks
for the clarification.


Sun, 11 Jul 2004 01:59:04 GMT  
 Question about SAFEARRAYS and deleteing them
If the code indeed looks like what you show, then it is in error.
"strings" is clearly an [in] parameter and should not be modified, nor
its contents deallocated. I don't have a copy of the book to check
though.
--
With best wishes,
    Igor Tandetnik

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


Quote:
> I'm reading a COM+/ATL book (Andrew Troelsen-- very good), and in the
> section on SAFEARRAYS he has some code like so:

> STDMETHOD CCoSafeArray::UseThisSafeArrayOfStrings(VARIANT strings)
> {
> .
> .
> .
>     SAFEARRAY *pSA = strings.parray;
> .
> .
> .
> .
>     SafeArrayUnaccessData(pSA);
>     SafeArrayDestroy(pSA);  //what the...?

> }

> My question is: why am I destroying the SAFEARRAY?  Up at the top of
the
> function, I didn't allocate any memory for it-- I'm just pointing to
the
> incoming parameter's copy of the array.  Maybe I'm mistaken, and
assigning a
> SAFEARRAY pointer to another array somehow allocates memory in the
> background?  Or do you think this is a typo on the author's part?
Thanks
> for the clarification.



Sun, 11 Jul 2004 03:22:06 GMT  
 Question about SAFEARRAYS and deleteing them
My experience is: when I pack a safearry into a variant as input parameter,
I have to set the parameter as [in]VARIANT * var, otherwise the server
cannot get correct data from VB client (C++ client no problem). The server
should not destroy the embeded safearray passed via *var in this case.

Anybody use [in]VARIANT var pass safearrays with successful VB client usage?

--
Jack


Quote:
> I'm reading a COM+/ATL book (Andrew Troelsen-- very good), and in the
> section on SAFEARRAYS he has some code like so:

> STDMETHOD CCoSafeArray::UseThisSafeArrayOfStrings(VARIANT strings)
> {
> .
> .
> .
>     SAFEARRAY *pSA = strings.parray;
> .
> .
> .
> .
>     SafeArrayUnaccessData(pSA);
>     SafeArrayDestroy(pSA);  //what the...?

> }

> My question is: why am I destroying the SAFEARRAY?  Up at the top of the
> function, I didn't allocate any memory for it-- I'm just pointing to the
> incoming parameter's copy of the array.  Maybe I'm mistaken, and assigning
a
> SAFEARRAY pointer to another array somehow allocates memory in the
> background?  Or do you think this is a typo on the author's part?  Thanks
> for the clarification.



Sun, 11 Jul 2004 03:36:25 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Copy 1D safeArray to 2D safearray

2. How to create safearray or safearray?

3. Accessing Safearray of Safearrays in C++

4. Deleteing files based on wildcards in the name

5. Modifying and Deleteing a selected xmlnode

6. Problems deleteing a file via VC++ 5

7. Deleteing 10% of records in a huge table having no index

8. Deleteing files

9. About deleteing arrays

10. Deleteing a directory

11. Deleteing additional Dialogs

12. Deleteing files in C++

 

 
Powered by phpBB® Forum Software