Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Runtime callable wrapper (RCW) scope - process or application domain?

What is the scope of Runtime Callable Wrapper (RCW), when referencing unmanaged COM objects? According to the docs:

The runtime creates exactly one RCW for each COM object, regardless of the number of references that exist on that object.

If I had to "guess" - this explanation should mean "one per process", but is it really? Any additional documentation will be very welcome.

My application runs in its own application domain (it is Outlook addin), and I would like to know what happens if I use Marshal.ReleaseComObject(x) in a loop until it's count reaches 0 (as recommended). Will it release references from other addins (running in other application domain in the same Outlook process)?

EDIT: Perfect - now the confusion is even bigger. Based on the 2 answers (from Lette and Ilya) we have 2 different answers. The official MSDN doc says per process (for ver. 2.0+), but it is missing this sentence for ver. 1.1 of the doc.

In the same time, in Mason Bendixen's article, it says it's per appdomain.

As his article is old (April 2007), I have send him an email asking for clarification, but if someone else has to add something, please do.

Thanks

like image 645
Sunny Milenov Avatar asked Oct 01 '08 19:10

Sunny Milenov


People also ask

What is RCW in asp net?

The common language runtime exposes COM objects through a proxy called the runtime callable wrapper (RCW). Although the RCW appears to be an ordinary object to . NET clients, its primary function is to marshal calls between a . NET client and a COM object.

What is RCW and ccw?

CCW - COM Callable Wrapper where the dlls which creted using . NET environment and using this COM to VB or other applications. RCW - Runtime Callable Warapper where the dlls created in any prior version of . net like VB6 and adding those DLLs to . NET environment using add reference and some other import options.

What is COM callable wrapper in C#?

COM callable wrappers are invisible to other classes running within the . NET runtime. Their primary purpose is to marshal calls between managed and unmanaged code; however, CCWs also manage the object identity and object lifetime of the managed objects they wrap.


1 Answers

In managed, we have a per app domain cache mapping canonical IUnknowns back to RCWs. When an IUnknown enters the system (through a marshal call, through activation, as a return parameter from a method call, etc.), we check the cache to see if an RCW already exists for the COM object. If a mapping exists, a reference to the existing RCW is returned. Otherwise a new RCW is created and a cache mapping is added.

from Mason's Blog

like image 105
Ilya Ryzhenkov Avatar answered Oct 16 '22 14:10

Ilya Ryzhenkov