COM rules always apply.
"Steve" <no@mail> wrote in message
news:1174918270.52578.0@iris.uk.clara.net...
> Yes, I realise that. But consider this:
>
> - IUnknown::QueryInterface returns an IntPtr to an interface. The
> reference count is 1.
> - GetTypedObjectForIUnknown is called to generate a RCW. It generates a
> new RCW, now the reference count is 2.
> - I use Marshal.ReleaseComObject to release the original reference.
>
> That's all fine. We have 1 reference to the interface, that of the RCW.
> Now consider this situation.
>
> - IUnknown::QueryInterface returns an IntPtr to an interface. The
> reference count is N.
> - GetTypedObjectForIUnknown is called to generate a RCW. It has already
> generated a RCW for this object in the past so the reference count is
> unchanged.
> - I use Marshal.ReleaseComObject to release the original reference. This
> decreases the count back to N-1, prematurely freeing the object.
>
> Am I misunderstanding something fundamental here?
>
> Regards
> Steve
>
>
> Michael Phillips, Jr. wrote:
>> Per the MSDN documentation, the object returned is a runtime callable
>> wrapper.
>>
>> The runtime callable wrapper maintains and releases the interface
>> pointers. See:
>>
http://msdn2.microsoft.com/en-us/library/8bwh56xe.aspx >>
>> "Steve" <no@mail> wrote in message
>> news:1174653010.23769.0@damia.uk.clara.net...
>>> Hello,
>>>
>>> Say I have an interface from IUnknown::QueryInterface that I want
>>> available in my .Net program. When QueryInterface returns, I am
>>> responsible for Release()ing it, but depending on whether
>>> GetTypedObjcetForIUnknown has already wrapped that object, it may or may
>>> not increase the reference count on the COM object. How do I know when
>>> to Release()?
>>