Windows 允许使用 COM 对象无需注册 COM dll一个>.
Windows allows use of a COM object without having to register the COM dll.
机制是在应用程序的清单中包含一个依赖程序集":
The mechanism is to include a "dependent assembly" in the application's manifest:
MyProgram.exe.manifest
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
<assemblyIdentity type="win32" name="myapp.exe" version="1.2.3.4" />
<dependency>
<dependentAssembly>
<assemblyIdentity type="win32" name="Contoso.Frobber" version="5.1.81.4" />
</dependentAssembly>
</dependency>
</assembly>
然后你的文件夹包含:
MyProgram.exe
MyProgram.exe.manifest
(如果您使用的是外部清单;也可以嵌入在 RT_MANIFEST
资源中)Contoso.Frobber.manifest
(COM DLL 清单)confrob.dll
(包含我们要使用的 COM 类的 dll)MyProgram.exe
MyProgram.exe.manifest
(if you're using an external manifest; could also be embedded at RT_MANIFEST
resource)Contoso.Frobber.manifest
(the COM DLL manifest)confrob.dll
(the dll containing the COM classes we want to use)COM dll 的程序集清单包含:
with the COM dll's assembly manifest containing:
Contoso.Frobber.manifest
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity type="win32" name="Contoso.Frobber" version="1.0.0.0" />
<file name = "confrob.dll">
<comClass
progid="Frobber.Gizmo"
clsid="{00028C00-0000-0000-0000-000000000046}"
description="Gizmo Frobber by Contoso"
threadingModel = "Apartment" />
<typelib
tlbid="{00028C01-0000-0000-0000-000000000046}"
version="1.0"
helpdir=""/>
</file>
</assembly>
非常好.我现在可以使用(本机或 .NET)可执行文件中的 COM 对象,而无需注册 COM 对象.
Excellent. i can now use a COM object from a (native or .NET) executable without having to register the COM object.
现在我想使用 一个 ASP.NET 网站中的 COM 对象,而不注册 COM 对象.
Now i want to use a COM object from an ASP.NET web-site, without registering the COM object.
可能吗?
Windows 还允许 exe 调用 .NET 库,而无需安装将 .NET 程序集放入全局程序集缓存中.
Windows also allows an exe to call a .NET library, without having to install the .NET assembly into the Global Assembly Cache.
虽然我现在无法测试它,但我很确定这可行:
Although I can't test it right now I am pretty sure that this works:
如果 DLL 的清单是外部的,则在通过 LoadLibrary
加载 DLL 时通常会忽略它(根据 MSDN).如果清单被嵌入到 DLL 中,它通常会被尊重.
IF the manifest for a DLL is external it will usually be ignored when the DLL is loaded via LoadLibrary
(according to MSDN). IF the manifest is embedded into the DLL it is usually honored.
将清单嵌入到 ASP.NET 应用程序(即代码隐藏 DLL)中 - 有关如何执行此操作的一些方法,请参阅 这里和这里和这里.
Embed the manifest into the ASP.NET application (i.e. code-behind DLL) - for some ways on how to do this see here and here and here.
更新 - 根据评论:
以上是一种解决方法,因为没有通用的方法来做到这一点(隔离),至少 ASP.NET 创建者并没有打算这样做 - 例如,上述解决方法在以下情况下不起作用应用程序无法编译为 DLL...
The above is a workaround as there is no general way to do this (isolation), at least the ASP.NET creators haven't intended this to be possible - for example the above workaround won't work in cases where the application does not compile to a DLL...
这篇关于来自 ASP.NET 的免注册 COM?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!