gpt4 book ai didi

c# - 为什么以及何时应该让我的程序集对 Com Components 可见?

转载 作者:太空狗 更新时间:2023-10-30 00:38:50 24 4
gpt4 key购买 nike

我有一个 Mvc 应用程序,我有这个选项:

// Setting ComVisible to false makes the types in this assembly not visible 
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

不知道这个能干什么,是不是安全设置?

何时选择 ComVisible(false) 以及何时选择 ComVisible(true)?

我搜索 Com 组件,了解这是什么,然后我找到了这个定义:

Component Object Model (COM) is a binary-interface standard for software components introduced by Microsoft in 1993. It is used to enable inter-process communication and dynamic object creation in a large range of programming languages. COM is the basis for several other Microsoft technologies and frameworks, including OLE, OLE Automation, ActiveX, COM+, DCOM, the Windows shell, DirectX, UMDF and Windows Runtime.

这对我来说意味着,Com 组件是应用程序之间通信的一种方式,但我不确定我对这个定义的理解是否正确。

你能用简单的话(例子)告诉我,为什么以及什么时候我应该使 ComVisible(真)?

最佳答案

当您需要将程序集中的公共(public)方法和函数公开给其他不是用 .NET 编写的应用程序时,您可以将 ComVisible 属性设置为 true,然后这些应用程序可以使用 Microsoft 的 COM(一种绑定(bind)的标准化接口(interface))使用程序集中的功能到运行时的组件。

进一步阅读:https://blogs.msdn.microsoft.com/cristib/2012/10/31/how-com-works-how-to-build-a-com-visible-dll-in-c-net-call-it-from-vba-and-select-the-proper-classinterface-autodispatch-autodual-part12

示例:https://richnewman.wordpress.com/2007/04/15/a-beginner%E2%80%99s-guide-to-calling-a-net-library-from-excel

关于c# - 为什么以及何时应该让我的程序集对 Com Components 可见?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37986402/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com