Re: import directive in VC2005
"Zf" <Zf@discussions.microsoft.com> wrote in message
I am porting some COM projects created in VS97 to VS2005. One thing I
noticed is that the functions generated in the TLI files are
different with VS97 and VC2005. In the VC2005 version, the IUnknown
pointer of the parameter is put into a IUnkownPtr smart pointer, but
with false as the second parameter, which will not increase the
reference count of the originally returned pointer. But when leaving
the generated function, the smart pointer will decrease the reference
This is normal. Interface pointer returned from a method call as [out]
parameter is AddRef'ed by that method, and should be eventually
Release'd by the caller. So it is correct for a smart pointer to assume
ownership of an already AddRef'ed pointer without AddRef'ing it again.
This causes my application crash as the COM object is
released when the count goes to 0.
This means the method is in error, by returning a pointer without
AddRef'ing it first.
But in the VS97 generated
functions, it just returns the original IUnknown pointer, and no
extra reference count decrease.
It was your responsibility to Release that pointer, which you didn't.
You just happened to have two reference counting bugs that, by accident,
My question is that is this the designed behaviour of ATL8 and ATL3?
And If I can ask the import directive not to put the original pointer
into a smart pointer in VC2005, or I can ask the smart pointer
creation to add reference count?
You should fix bugs in your code, or ask component authors to fix bugs
With best wishes,
With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925