"注册为COM互操作" VS"使组装COM可见的QUOT;操作、QUOT、COM、VS

2023-09-02 21:43:23 作者:情深不及⑨伴

这两个选项之间的真正区别是什么?我所知道的是:

注册为COM互操作 此选项执行regasm的组装和注册组件,在注册表中所有的COM像注册表项的COM组件(也可能不是)。 这是否步骤生成一个TLB文件?还有什么做?

有时候,我看到当我编译项目中的TLB的产生,但有时没有,这是为什么?

请组件COM可见 这是否一个具有装配上什么样的影响?如果我有以下类型此组件内,我还需要指定使组装COM可见即使我喜欢的类型被标记为标记有ComVisible特性?

  [GuidAttribute(02810C22-3FF2-4fc2-A7FD-5E103446DEB0),标记有ComVisible特性(真)
公共接口IMyInterface的
{
}
 

解决方案

使组装COM可见是一个大铁锤作出的所有的公开类型的组件[标记有ComVisible特性。很少可取的,你将要选择你想成为可见的具体类型,就像你在你的代码片段一样。

该组件被建手机注册qq显示注册失败 就像这样 如果这样的话要怎么办 能结束这个状态吗

在,它需要进行登记,以便它通过COM客户端变为可用。这包括写在注册表中的 HKLM Software Classes下 CLSID {GUID} 部分注册表项。你可以自己动手通过运行 Regasm.exe / codeBase的/ TLB 或者你可以把它留给构建系统构建装配后自动执行。这正是注册为COM互操作一样。 VS需要运行提升到有写权限的注册表项,其中一个原因使其可选。或者你只是不想注册,构建服务器上常见的。我不能,为什么你有时不能得到.TLB没有更多的诊断意见。

What is the real difference between these two options? What I know is:

Register for COM Interop This options executes regasm on the assembly and registers the assembly as an COM component(or maybe not) in the registry with all COM like registry entries. Does this step generates a TLB file? What else is done?

Sometimes I see a tlb is generated when I compile the project but sometimes not, why is this?

Make assembly COM visible What effect does this one has on an assembly? If I have the following type inside this assembly, do I still need to specify the "Make assembly COM Visible" even though my type is marked as ComVisible?

[GuidAttribute("02810C22-3FF2-4fc2-A7FD-5E103446DEB0"), ComVisible(true)]
public interface IMyInterface
{
}

解决方案

"Make assembly COM visible" is a big hammer to make all public types in the assembly [ComVisible]. Rarely desirable, you will want to select the specific types that you want to be visible, like you did in your snippet.

After the assembly is built, it needs to be registered so that it becomes usable by COM clients. This involves writing registry keys in the HKLMSoftwareClassesCLSID{guid} portion of the registry. You can do it yourself by running Regasm.exe /codebase /tlb or you can leave it up to the build system to do it automatically after building the assembly. Which is what "Register for COM interop" does. VS needs to run elevated to have write access to those registry keys, one reason for making it optional. Or you just don't want to register it, common on build servers. I can't comment on why you'd sometimes not get the .tlb without more diagnostics.