C#:Regasm 为我的 COM DLL 中的每个类生成注册表项?

发布于 2024-07-24 22:18:43 字数 506 浏览 3 评论 0原文

我正在用 C# 编写一个类库 (IE BHO),目前正在处理大量我认为来自 REGASM 生成的注册表项的垃圾输出。

简短的版本是这样的:我只想向 IE(以及 COM 的其余部分)公开少数类(当前:一个类)。 只有一个类设置了 ClassInterfaceAttribute 和 GUID 内容,并且我可以测试该附加组件仅需要该类的 COM 注册表项 - 然而,REGASM 为整个项目中的每个类生成 GUID 和注册表项。

这很烦人,而且有些令人不安,因为我不希望我的类名出现在用户的注册表中,除非它们绝对必须在那里。

公平地说,许多其他类都被标记为公共,因为我在同一解决方案中另一个项目的驱动程序应用程序中使用它们,以解决 IE 的调试黑洞...

总的来说,我对 COM 仍然很陌生(尤其是与 .Net 相关),我想知道隐藏所有其他课程免遭高潮的最佳方法是什么? 或者,至少,为什么这些类——即使它们被标记为公共——在我没有为它们设置任何 COM 标志时仍然出现?

谢谢!

I'm writing a class-library (IE BHO) in C# and currently wrangling with the large volume of what I think is junk output coming from REGASM's generated registry keys.

The short version is this: I only want to expose a handful of classes (currently: ONE class) to IE (and the rest of COM). Only one class has the ClassInterfaceAttribute and GUID stuff set, and I can test that the add-on only requires the COM registry keys for this class -- and yet, REGASM generates GUIDs and registry keys for every class in the entire project.

This is annoying and somewhat disturbing as I do not want my class names sitting in users' registry unless they absolutely have to be there.

To be fair, many of those other classes are marked public because I use them in a driver app from another project in the same solution, to work around IE's debugging black hole...

I'm still very green to COM in general (especially relating to .Net) and I was wondering what is the best way to hide all my other classes from regasm? Or, at least, why these classes that -- even though they are marked public -- are showing up when I haven't set any of the COM flags for them?

Thanks!

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

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

发布评论

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

评论(4

半﹌身腐败 2024-07-31 22:18:43

对于不需要 public 修饰符的内容,请使用 internal 访问修饰符。 对于真正需要公共访问的内容,请使用 ComVisible 属性来部分隐藏它。

例如:

[ComVisible(false)]
public class ClassToHide {
    //whatever
};

public class ClassToExpose {

     public void MethodToExpose() {}

     [ComVisible(false)]
     public void MethodToHide() {}
};

所有公共类的所有公共成员函数和成员变量默认都是 COM 可见的。 因此,首先考虑将它们设为内部的,如果您确实需要将它们公开,则使用 ComVisible 将它们隐藏在 COM 中。

Use internal access modifier for stuff that doesn't need to have public modifier. For stuff that really needs public access use ComVisible attribute to partially hide it.

For example:

[ComVisible(false)]
public class ClassToHide {
    //whatever
};

public class ClassToExpose {

     public void MethodToExpose() {}

     [ComVisible(false)]
     public void MethodToHide() {}
};

All public member functions and member variables of all public classes are COM-visible by default. So first think of making them internal and if you really need them public hide them from COM with ComVisible.

一张白纸 2024-07-31 22:18:43

尝试使用 /regfile 开关 - 这将输出一个 reg 文件,而不是直接将所有类名写入注册表。

当您拥有 .reg 文件时,您可以删除任何不想添加到目标系统注册表的条目,并仅将这些值部署到目标计算机。 根据您选择部署软件的方式,这可能会更容易,并且您不必更改任何类型的代码。

事实上,如果您无法访问源代码,这将是实现这一目标的唯一方法。

Try using the /regfile switch - this will output a reg file rather than directly writing all your class names to the registry.

When you have the .reg file you can remove any entries you dont want to be added to the target systems registry, and deploy only those values to the target machine. Depending on how you choose to deploy your software, this might be easier and you would not have to change the code for any of your types.

In fact if you dont have access to the sourcecode, this would be the only way to achieve this.

青朷 2024-07-31 22:18:43

我写了一个COM组件也有同样的问题。

我将所有非 COM 函数分离到一个单独的辅助 DLL 中。 COM DLL 仅包含需要注册的代码。 其他一切都通过辅助 DLL 访问。

我发现有一种简单的方法可以确保将来的代码不会意外地被标记为 public 而不是 internal 并显示在注册表中。

I wrote a COM component with the same problems.

I separated all the non-COM functions into a separate helper DLL. The COM DLL only contains the code that needs to be registered. Everything else is accessed through the helper DLL.

I found that an easy way to make sure that future code wouldn't accidentally be marked as public rather than internal and show up in the registry.

轻许诺言 2024-07-31 22:18:43

在 AssemblyInfo 文件中将 ComVisible 属性设置为 false,并设置仅对所需的类应用 ComVisible。

Set ComVisible attribute to false in AssemblyInfo file and set apply ComVisible for only the desired classes.

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