COM程序如何找到为COM Interop注册的.NET DLL? [英] How Does a COM Program Locate a .NET DLL Registered for COM Interop?

查看:159
本文介绍了COM程序如何找到为COM Interop注册的.NET DLL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个客户想要使用VB6中的.NET DLL.它们被设计为支持反向互操作,并且一切正常...除了:在两个不同的目录中有两个单独的VB6程序.似乎有必要执行以下一项操作:

One customer wants to consume our .NET DLLs from VB6. They are designed to support reverse interop and all works fine... except: There are two separate VB6 programs in two different directories. It seems it's necessary to do one of:

  1. 将.NET DLL复制到两个目录中,或
  2. 在GAC中安装.NET DLL

这是客户的观察,并得到 RegAsm的支持文档:

This is the customer's observation and also supported by the RegAsm documentation:

使用进行程序集注册后 Regasm.exe,您可以将其安装在 全局程序集缓存,以便它可以 从任何COM客户端激活.如果 组装只会是 由单个应用程序激活,您 可以将其放在该应用程序的 目录.

After registering an assembly using Regasm.exe, you can install it in the global assembly cache so that it can be activated from any COM client. If the assembly is only going to be activated by a single application, you can place it in that application's directory.

我对此感到困惑.

第一点困惑:

据我了解,COM运行时使用Prog ID/Class ID定位DLL.当我在注册表中的类ID条目中查看时,我在CodeBase项中看到了.NET DLL的完整路径.为什么使用Prog ID/Class ID的COM程序找不到使用CodeBase的.NET DLL?

As far as I understand, the COM runtime locates the DLL using the Prog ID / Class ID. When I look in the registry at the Class ID entry, I see the full path to the .NET DLL in the CodeBase key. Why is it that a COM program using the Prog ID / Class ID doesn't locate the .NET DLL using the CodeBase?

第二点困惑:

GAC特定于.NET.它如何解决COM引用?

The GAC is specific to .NET. How is it involved in resolving COM references?

推荐答案

您是正确的,COM使用ProgId来获取ClassId来获取要加载的COM服务器.对于.NET COM dll,COM服务器实际上是MSCOREE,而不是.NET dll({CLSID}/localserver32下默认密钥的值).然后,MSCOREE而不是COM,可以使用它想要的任何规则来查找.NET程序集.

You're correct COM uses the ProgId to get to the ClassId to get to the COM server to load. In the case of .NET COM dlls, the COM server is actually MSCOREE, not the .NET dll (the value of the default key under {CLSID}/localserver32). MSCOREE, not COM, then can use whatever rules it wants to find the .NET assembly.

在这一点上,我不知道.NET到底是做什么的-这需要测试.您可以使用 FUSLOGVW 来监视自己.但是我可以猜测它像加载任何其他.NET程序集一样加载程序集.

At this point, I don't know what .NET really does - that would require testing. You could watch yourself using FUSLOGVW. I can however guess it loads the assembly like it loads any other .NET assembly.

假设它只是使用ClassName值调用Assembly.Load(),它将遵循

Assuming it just calls Assembly.Load() with the ClassName value, it'll follow the .NET binding rules. First look in the GAC, if not found will probe - so if a codebase is defined, it'll only look there, otherwise it will probe based on the application base (by default the directory of the app [but not for ASP.NET]).

我认为这与您在阅读中所读的内容相吻合.

I think that fits with what your read in regasm.

您的问题太旧了,我认为它已经 OBE ,但是您用于放置程序集的规则使用代码库或在GAC中的 与com互操作相同.每种情况都是不同的,并且我做不到足够的.NET来放弃任何深刻的见解.我赞成安装xcopy,所以我会在app目录中使用它(并使用免费注册的COM ),但还有其他考虑因素,例如两个vb应用程序必须使用相同版本的COM对象.

Your question is so old I assume it's been OBE, but the rules you'd use for putting assemblies in the app directory, use a codebase, or in the GAC are the same with and w/o com interop. Every situation is different and I haven't done enough .NET to give up any deep insights. I favor xcopy installs so I'd go with in the app directory (and use registration free COM) but there are other considerations like if the two vb apps must use the same version of the COM object.

这篇关于COM程序如何找到为COM Interop注册的.NET DLL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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