Questions tagged [rcw]

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.

Runtime Callable Wrapper

The runtime creates exactly one RCW for each COM object, regardless of the number of references that exist on that object. The runtime maintains a single RCW per process for each object. If you create an RCW in one application domain or apartment, and then pass a reference to another application domain or apartment, a proxy to the first object will be used. As the following illustration shows, any number of managed clients can hold a reference to the COM objects that expose INew and INewer interfaces.

http://msdn.microsoft.com/en-us/library/8bwh56xe(v=vs.110).aspx

63 questions
26
votes
1 answer

Why a RaceOnRCWCleanup error when closing a form with WebBrowser control on it?

VS2008, .NET 2, VB.NET, XP ... I have a Windows form, with a WebBrowser control and a Close button, which just does a Me.Close. The form's cancel button is set to the Close button, so that I can hit ESC to close the form. I set the DocumentText…
ChrisA
  • 4,163
  • 5
  • 28
  • 44
21
votes
5 answers

RCW & reference counting when using COM interop in C#

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…
Navaneeth K N
  • 15,295
  • 38
  • 126
  • 184
13
votes
2 answers

COM exceptions on exit with WPF

After execution both of the following test cases, a COM execution is printed to the console. What am I doing wrong? If I run either test singly, or if I run both tests together, the exception is written to the console exactly once. This makes me…
Patrick Linskey
  • 1,124
  • 1
  • 13
  • 24
8
votes
2 answers

Can't get all excel processes to stop when closing through Powershell

With this code, I am opening excel(with visible = false so the user cannot see it), writing to a workbook, and then either opening excel(making it visible) after the script ends or closing it completely without saving. When I save excel, leave it…
danualpxc
  • 83
  • 1
  • 6
7
votes
2 answers

RCW Finalizer Access Violation

I am using COM interop for creating a managed plugin into an unmanaged application using VS2012/.NET 4.5/Win8.1. All the interop stuff seems to be going ok, but when I close the app I get an MDA exception telling me AV's have happened while…
obiwanjacobi
  • 2,413
  • 17
  • 27
7
votes
1 answer

how to tell if a COM object has been separated from its underlying RCW without relying on exceptions?

A way to tell if the COM Object's reference count has reached 0 is by attempting to access one of its members and catch the resulting InvalidComObjectException, which is not very elegant and doesn't seem to lend itself well. Another way is to call…
J Smith
  • 2,375
  • 3
  • 18
  • 36
7
votes
1 answer

Releasing a COM object reference safely from .NET

I have read a lot of articles on the net about releasing RCW's safely, and it seems to me that no one can agree on exactly what needs to be done in what order, so I'm asking you guys for your opinions. For example, one could do this: object target =…
Christian Hayter
  • 30,581
  • 6
  • 72
  • 99
7
votes
1 answer

VS2008 UnitTesting - detached RCW with Office Application objects (PowerPoint, etc.)

BACKGROUND I am automating an PowerPoint 2007 via C# I am writing unittests using the built-in unit testing of Visual Studio (Microsoft.VisualStudio.TestTools.UnitTesting) for my code I am well relatively experienced in automating the Office 2007…
namenlos
  • 5,111
  • 10
  • 38
  • 38
6
votes
1 answer

What is the difference between a COM string (BSTR) and a .NET string?

Is it just the way the bytes are combined to "encode" the data? I'm curious because I wonder how an RCW automatically takes a .NET string and transforms it into a COM BSTR. I'm guessing it just forms a valid COM BSTR transformed from the .NET…
richard
  • 12,263
  • 23
  • 95
  • 151
6
votes
1 answer

When does the .NET runtime hold a reference count > 1 for COM objects?

Until recently, I believed that the .NET runtime only increases the reference count of COM objects by 1 when creating a runtime-callable wrapper, and that only one such runtime-callable wrapper is created for any given COM object. If I'm not…
Wim Coenen
  • 66,094
  • 13
  • 157
  • 251
6
votes
1 answer

How to get LINQPad to Dump() System.__ComObject references?

I am playing around with using LINQPad to rapidly develop small ArcObjects (a COM-based library for ESRI's ArcGIS software) applications and have had some success in using it to Dump() the properties of COM objects that I initialize from .NET, but…
blah238
  • 1,796
  • 2
  • 18
  • 51
5
votes
3 answers

C# wrapper interface error: E_NOINTERFACE

I am trying to produce a C# wrapper for a COM object that I have (named SC_COM.dll), but am having some issues linking it with Visual Studio 2008 (running Vista). I need to do this registration-free with the COM DLL--I'm using a manifest file to…
DashRantic
  • 1,448
  • 4
  • 19
  • 32
5
votes
2 answers

VS2010 will not display project properties ("underlying RCW")?

Only sometimes (I haven't yet noticed a pattern), VS2010 shows the following error (where I'd expect the body of the property page to be) when I right-click on a project (various types of projects) and select "Properties": I can typically view the…
lance
  • 16,092
  • 19
  • 77
  • 136
5
votes
2 answers

Addref on COM RCW

Is it possible to increase the RCW reference count on an unknown interface? (i.e. not the reference count on the underlying COM object) I have some old COM server code int Method1(object comobject) { try { // do something with comobject …
adrianm
  • 14,468
  • 5
  • 55
  • 102
5
votes
1 answer

Does a wrapper class calling a COM component through C# need to implement the Dispose pattern?

I have a class written in c# which is acting as a wrapper around a COM component. The COM component is early bound and the RCW has been generated by Visual Studio. Should I implement a dispose pattern in my wrapper class to clean up the COM…
Sci-fi
  • 759
  • 4
  • 8
  • 12
1
2 3 4 5