COM TreatAs 如何(以及何时)工作?
我正在使用 查看 vsjitdebugger.exe
的注册表访问Process Monitor,我注意到有时它通过以下方式查询注册表(省略了一些信息):
HKCU\Software\Classes\CLSID\{some-guid} NAME NOT FOUND Desired Access: Read
...
HKCU\Software\Classes\CLSID\{some-guid}\TreatAs NAME NOT FOUND Desired Access: Query Value
...
HKCU\Software\Classes\CLSID\{some-guid}\InprocServer32 NAME NOT FOUND Desired Access: Read
...
HKCR\CLSID\{24E669E1-E90F-4595-A012-B0FD3CCC5C5A}\InprocServer32 SUCCESS Desired Access: Read
有关MSDN 上的TreatAs 显示它允许为将调用的另一个 COM 服务器而不是原始服务器指定 GUID。
我无法找到有关此密钥的更多信息,并且无法在我自己的 COM 对象上使用它:我有同一个 COM 对象的两种不同实现(在 2 个单独的 DLL 中,有 2 个单独的 GUID) ,当我的进程通过 GUID 创建对象时,我希望它创建另一个对象(通过 TreatAs 中指定的 GUID)。不幸的是,Windows 似乎立即尝试查询 HKCU\Software\Classes\CLSID\{my-guid}\InprocServer32,而不是首先查找 TreatAs。
我的问题基本上是关于 TreatAs 的规则,何时以及如何查询它?
I was looking at the registry access of vsjitdebugger.exe
using Process Monitor, and I noticed that sometimes it queries the registry in the following manner (some info omited):
HKCU\Software\Classes\CLSID\{some-guid} NAME NOT FOUND Desired Access: Read
...
HKCU\Software\Classes\CLSID\{some-guid}\TreatAs NAME NOT FOUND Desired Access: Query Value
...
HKCU\Software\Classes\CLSID\{some-guid}\InprocServer32 NAME NOT FOUND Desired Access: Read
...
HKCR\CLSID\{24E669E1-E90F-4595-A012-B0FD3CCC5C5A}\InprocServer32 SUCCESS Desired Access: Read
Information on TreatAs on MSDN shows that it allows specifying a GUID for another COM server which will be called instead of the original.
I wasn't able to find much more information about this key, and I wasn't able to use it on my own COM object: I have two different implementations of the same COM object (in 2 separate DLLs, having 2 separate GUIDs), and when my process creates the object via GUID, I'd like it to create the other object instead (via GUID specified in TreatAs). Unfortunately, it seems that Windows immediately tries to query HKCU\Software\Classes\CLSID\{my-guid}\InprocServer32
, instead of first looking for TreatAs.
My question basically is about rules of TreatAs, when and how does it get queried?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
TreatAs 功能的工作原理非常简单:通过请求
CoCreateInstance
COM 对象的实例,COM 子系统会检查 TreatAs 键,并在找到时尝试实例化替换/模拟类并透明地返回它而不是请求的 CLSID。这样,调用者就透明地获得了仿真对象的接口。该功能很少使用,但仍在使用。您可以使用 EnumerateTreatAsClasses 实用程序枚举当前活动的 TreatAs 类。该功能是挂钩 COM 类实例化的方法之一。
TreatAs feature works pretty simple: with a request to
CoCreateInstance
an instance of a COM object, COM subsystem checks for TreatAs key and, when found, attempts to instantiate a substitution/emulation class and transparently return it instead of requested CLSID. The caller, thus, obtains an interface of an emulation object transparently.The feature is rarely used, but still used. You can enumerate currently active TreatAs classes using EnumerateTreatAsClasses utility. The feature is one of the method to hook COM class instantiation.