IDL 中不可创建的组件类的目的是什么?

发布于 2024-07-19 04:48:30 字数 228 浏览 3 评论 0原文

在 IDL 中声明如下不可创建的组件类的原因是什么?

[
    uuid(uuidhere),
    noncreatable
]
coclass CoClass {
    [default] interface ICoClass;
};

我的意思是这样的类无论如何都不会注册到COM。 在 IDL 文件和编译该 IDL 文件生成的类型库中提到它的原因是什么?

What is the reason for declaring noncreatable coclasses like the following in IDL?

[
    uuid(uuidhere),
    noncreatable
]
coclass CoClass {
    [default] interface ICoClass;
};

I mean such class will not be registered to COM anyway. What's the reason to mention it in the IDL file and in the type library produced by compiling that IDL file?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

〆凄凉。 2024-07-26 04:48:30

当您想要阻止客户端使用默认类工厂实例化对象但仍具有用于日志记录、调试等的正确 CLSID 时,noncreatable 非常有用; 请参阅 http://www.eggheadcafe.com/ 的示例software/aspnet/29555436/noncreatable-atl-object.aspx 的问题已通过这种方式得到正确解决。

noncreatable is good when you want to stop clients from instantiating the object with the default class factory yet still have a proper CLSID for logging, debugging &c; see an example at http://www.eggheadcafe.com/software/aspnet/29555436/noncreatable-atl-object.aspx of an issue which is properly resolved that way.

尹雨沫 2024-07-26 04:48:30

noncreatable 属性只是对对象使用者的提示——例如,.Net 和 VB6,当看到此属性时,将不允许客户端“以正常方式”创建对象,例如通过调用 New CoClass() [VB6]。

然而,COM 服务器的类工厂是决定是否允许创建给定类的对象的明确权威——因此事实上,有可能一个类被标记为不可创建,但类工厂却允许创建对象。创建的。 为了避免这种情况,请确保相应地更新类工厂。

事实上,在 IDL 中提及不可创建的类是可选的。 但请注意,无论如何,包含它们至少会给您带来一个好处:midl 将创建 CLSID_CoClass 常量等。

The noncreatable attribute is just a hint to the consumer of the object -- .Net and VB6, for example, when seeing this attribute, will not allow the client to create the object "the normal way", e.g. by calling New CoClass() [VB6].

However, the COM server's class factory is the definite authority for deciding whether it allows objects of given class to be created or not -- so in fact, it is possible that a class is marked noncreatable and yet, the class factory allows objects to be created. To avoid such situations, make sure that you update your class factory accordingly.

Mentioning noncreatable classes in the IDL is in fact optional. Note, however, that you get at least one benefit from including them anyway: midl will create CLSID_CoClass constants etc.

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