Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RCW & reference counting when using COM interop in C#

Tags:

People also ask

What is an RCW in Washington state?

The Revised Code of Washington (RCW) is a compilation of all permanent laws now in force. It is a collection of Session Laws arranged by topic, with amendments added and repealed laws removed.

What is the difference between WAC and RCW in Washington state?

The Uniform Disciplinary Act is found in RCW 18.130 — this is the specific RCW that determines the threshold for formal discipline (what is considered a chargeable offense) for all health professions in Washington state. WACs are rules that provide interpretive support for those covered by RCWs.

What are regulations called in Washington state?

Washington Administrative Code (WAC) — Regulations of executive branch agencies are issued by authority of statutes. Like legislation and the Constitution, regulations are a source of primary law in Washington State. The WAC codifies the regulations and arranges them by subject or agency.

What is the primary law of the state of Washington?

The foremost source of state law is the Constitution of Washington. The Washington Constitution in turn is subordinate to the Constitution of the United States, which is the supreme law of the land.


I have an application that uses Office interop assemblies. I am aware about the "Runtime Callable Wrapper (RCW)" managed by the runtime. But I am not very sure how the reference count gets incremented. MSDN says,

RCW keeps just one reference to the wrapped COM object regardless of the number of managed clients calling it.

If I understand it correctly, on the following example,

using Microsoft.Office.Interop.Word;  static void Foo(Application wrd) {     /* .... */ }  static void Main(string[] args) {     var wrd = new Application();     Foo(wrd);     /* .... */ } 

I am passing the instance wrd to another method. But this doesn't increment the internal reference count. So I am wondering on what scenarios the reference count gets incremented? Can anyone point out a scenario where the reference count gets incremented?

Also I read some blog which says avoid using double dots when programming with COM objects. Something like, wrd.ActiveDocument.ActiveWindow. The author claims that compiler creates separate variables to hold the values which will increment the reference counter. IMHO, this is wrong and the first example proves this. Is that correct?

Any help would be great!