COM TreatAs 如何(以及何时)工作?

发布于 2024-10-04 11:06:36 字数 1038 浏览 11 评论 0原文

我正在使用 查看 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

北恋 2024-10-11 11:06:36

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文