运行时可调用包装器 (RCW) 范围 - 进程还是应用程序域? [英] Runtime callable wrapper (RCW) scope - process or application domain?

查看:10
本文介绍了运行时可调用包装器 (RCW) 范围 - 进程还是应用程序域?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在引用非托管 COM 对象时,运行时可调用包装器 (RCW) 的范围是什么?根据文档:

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

运行时只创建一个 RCW对于每个 COM 对象,无论存在于那个对象.

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.

我的应用程序在它自己的应用程序域中运行(它是 Outlook 插件),我想知道如果我在循环中使用 Marshal.ReleaseComObject(x) 直到它的计数达到 0(按照建议)会发生什么.它会释放来自其他插件(在同一 Outlook 进程中的其他应用程序域中运行)的引用吗?

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)?

完美 - 现在混乱更大了.基于 2 个答案(来自 Lette 和 Ilya),我们有 2 个不同的答案.官方 MSDN doc 说每个进程(对于ver. 2.0+),但是对于 缺少这句话版本1.1 文档.

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.

同时,在 Mason Bendixen 的文章中,它说它是每个应用程序域.

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

由于他的文章很旧(2007 年 4 月),我已经给他发了一封电子邮件,要求澄清,但如果其他人必须添加一些内容,请添加.

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.

谢谢

推荐答案

在托管中,我们有一个每个应用程序域缓存将规范 IUnknown 映射回RCW.当 IUnknown 进入系统(通过元帅呼叫,通过激活,作为回报方法调用中的参数等),我们检查缓存以查看是否有 RCWCOM 对象已经存在.如果存在映射,引用返回现有的 RCW.否则一个创建新的 RCW 和缓存映射已添加.

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.

来自梅森的博客

这篇关于运行时可调用包装器 (RCW) 范围 - 进程还是应用程序域?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆