免注册COM从ASP.NET? [英] Registration-Free COM from ASP.NET?

查看:126
本文介绍了免注册COM从ASP.NET?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Windows允许使用COM对象,而无需注册COM DLL

该机制包含一个的依赖程序集的在应用程序的清单:


  

MyProgram.exe.manifest

 <?XML版本=1.0编码=UTF-8独立=YES&GT?;
<装配manifestVersion =1.0的xmlns =瓮:架构 - 微软COM:asm.v1>
  < assemblyIdentity TYPE =win32的NAME =MyApp.exe将版本=1.2.3.4/>
  <&依赖性GT;
    < dependentAssembly>
      < assemblyIdentity TYPE =win32的NAME =Contoso.Frobber版本=5.1.81.4/>
    < / dependentAssembly>
  < /依赖性>
< /装配>


然后你的文件夹中包含:


  • MyProgram.exe

  • MyProgram.exe.manifest (如果您使用的是外部清单;也可以嵌入在 RT_MANIFEST 资源)

  • Contoso.Frobber.manifest (在COM DLL清单)

  • confrob.dll (包含我们要使用的COM类的DLL)

用包含COM DLL的程序集清单:


  

Contoso.Frobber.manifest

 <?XML版本=1.0编码=UTF-8独立=YES&GT?;
<装配的xmlns =瓮:架构 - 微软COM:asm.v1manifestVersion =1.0>   < assemblyIdentity TYPE =win32的NAME =Contoso.Frobber版本=1.0.0.0/>   <文件名=confrob.dll>      < comClass
            进程id =Frobber.Gizmo
            CLSID ={} 00028C00-0000-0000-0000-000000000046
            说明=小玩意儿Frobber由Contoso的
            的ThreadingModel =公寓/>      <类型库
            tlbid ={} 00028C01-0000-0000-0000-000000000046
            版本=1.0
            HELPDIR =/>
   < /文件>
< /装配>


出色。我现在可以使用由(本地或.NET)可执行的COM对象,而无需注册COM对象。

现在我想使用COM对象的一个ASP.NET网站,而无需注册的COM对象。

可能?


奖金颤振

Windows还允许 EXE调用.​​NET库,无需安装.NET程序集到全局程序集缓存


解决方案

虽然我不能测试它现在的我pretty确保此工作的:

如果清单的DLL是外部的,当DLL通过调用LoadLibrary 加载它通常会被忽略(根据的 MSDN )。中频清单被嵌入到该DLL它通常兑现。

嵌入清单到ASP.NET应用程序(即code-背后DLL) - 关于如何做到这一点看的这里这里 和的这里

更新 - 按评论:

以上是一个解决办法,因为没有通用的方法来做到这一点(隔离),至少在ASP.NET创建者无意这是可能的 - 例如上面的解决方法将无法在正常工作的情况下在哪里应用程序不编译到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>

And then your folder contains:

  • 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)

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>

Excellent. i can now use a COM object from a (native or .NET) executable without having to register the COM object.

Now i want to use a COM object from an ASP.NET web-site, without registering the COM object.

Possible?


Bonus Chatter

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:

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.

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.

UPDATE - as per comments:

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...

这篇关于免注册COM从ASP.NET?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆