如何将 COM 公开的 .NET 项目添加到 VB6(或 VBA)引用对话框? [英] How Add a COM-Exposed .NET Project to the VB6 (or VBA) References Dialog?

查看:27
本文介绍了如何将 COM 公开的 .NET 项目添加到 VB6(或 VBA)引用对话框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我根据特殊文章 构建和部署一个 .NET COM 程序集,作者:Phil Wilson.

I have created a .NET assembly that is exposed to COM according to the exceptional article Build and Deploy a .NET COM Assembly by Phil Wilson.

从某种意义上说,一切正常,因为 .NET 程序集已为 COM 正确注册,并且编译后的 COM 代码可以毫无问题地调用它.

And everything works fine in the sense that the .NET assembly is properly registered for COM, and compiled COM code can call it without any trouble.

唯一奇怪的是,在使用 VB 6.0 或 VBA 时针对 COM 公开的 .NET 程序集进行开发需要程序员浏览"到相关 .tlb 文件的确切文件位置,之后一切正常.也就是说,类库不会直接显示在引用"对话框中,因此您必须浏览到文件位置.

The only odd thing is that developing against the COM-exposed .NET assembly when using VB 6.0 or VBA requires that the programmer 'browse' to the exact file location of the associated .tlb file, after which everything works just fine. That is, the class library is not showing up directly within the References dialog box, so you must browse to the file location.

同样,COM 互操作方面确实 100% 有效;但是,我认为必须有一些设置可以使库在 VB 6.0 和 VBA 的引用"对话框中直接可见.

Again, the COM Interop aspects do work 100%; however, I would think that there must be some setting that would make the library directly visible within the References dialog for VB 6.0 and VBA.

有谁知道这个设置是什么?或者这是否应该通过注册自动为我发生?

Does anyone know what this setting would be? Or should this be happening automatically for me just by having it registered?

非常感谢您的任何建议...

Much thanks in advance for any advice...

迈克

编辑/更新

为了回答 jpoh 关于我是否使用/codebase 开关的问题,我使用的是 .msi 安装包,而不是明确使用 RegAsm.程序集已正确注册,这可以从以下事实看出:在 HKCRCLSID{myGUID}InprocServer32 中,CodeBase"键正确地保存了程序集的完整路径.编译后的 COM 组件对这个 dll 执行得很好,只有在使用 VB 6.0 或 VBA 对其进行开发时,它们才不会出现在引用对话框中.因此,我需要浏览"到正确的文件位置,之后它可以 100% 正常工作.

To answer jpoh's question about whether I'm using the /codebase switch, I'm using a .msi Setup Package, and not explicitly using RegAsm. The assembly is being correctly registered, which can be seen by the fact that within HKCRCLSID{myGUID}InprocServer32, the 'CodeBase' key correctly holds the full path to the assembly. Compiled COM components execute against this dll just fine, it's only when developing against it using VB 6.0 or VBA that they do not appear within the references dialog box. I therefore need to 'browse' to the correct file location, after which it works 100% fine.

更新 #2

经过进一步研究,似乎虽然类 GUID 已正确注册,但我的 .tlb 文件未注册.我不知道为什么不.注册 .tlb 文件应该在 HKCRInterface{myInterfaceGUID} 中为我的类所基于的接口放置一些注册表项,但这不会发生.奇怪的是,除了在 VB6 和 VBA 的引用对话框中的可发现性之外,这种缺少注册似乎并没有影响 dll 的功能.

Upon further research, it appears that, although the class GUIDs are being registered properly, my .tlb file is not being registered. I have no idea why not. Registering the .tlb file should put some registry entries for the interface on which my class is based at HKCRInterface{myInterfaceGUID}, but this is not occurring. Strange that this lack of registration does not seem to affect the dll's ability to function, other than its discoverability within VB6's and VBA's references dialog.

我的 .tlb 文件在安装项目中的属性似乎是正确的:PackageAs"属性设置为vsdpaDefault",Register"属性设置为vsdrfCOM".我很困惑为什么它不能成功安装在目标机器上.

The properties for my .tlb file within the Setup Project do seem to be correct: the 'PackageAs' property is set to 'vsdpaDefault' and the 'Register' property is set to 'vsdrfCOM'. I am puzzled as to why this would not be successfully installed on the target machine.

更新 #3

好的,事实证明安装项目没有成功构建...尽管它报告构建成功".

Ok, it turns out that the Setup Project is not being built successfully... despite it reporting that the "Build Succeeded".

实际上有一个构建警告(令人惊讶的是,警告,而不是错误)被报告为无法为文件名 'DotNetLibrary3.tlb' 创建注册信息".由于这是一个警告,而不是错误,因此编译显示构建成功"并且错误列表没有打开.

There is actually a build warning (amazingly, a warning, not an error) being reported that it as "Unable to create registration information for file name 'DotNetLibrary3.tlb'". Since this was a warning, and not an error, the compile was stating "Build Succeeded" and the Error List was not opening up.

跟踪这一点,当您在 Vista 是您的开发机器时尝试创建安装项目时,这似乎是一个问题,如下所述:

Tracking this down, it seems that this can be an issue when attempting to create a Setup Project when Vista is your development machine, as described here:

COM 类型库VS2008安装工程中的注册问题

这里描述了一个手动修复:

There is a somewhat manual fix described here:

反馈:无法创建注册信息对于名为文件名"的文件

我还没有尝试过修复,但我明天会尝试,如果解决了我会报告.

I have not tried the fix yet, but I will tomorrow and I'll report back if this solves it.

更新 #4

效果不太好...在 Vista 上运行时,按照该文章中的建议运行 RegCap.exe 似乎不起作用.由于 RegCap 实际上是由安装项目本身在创建 .msi 时在内部运行的,因此这并不奇怪.简而言之,安装项目几乎肯定会失败,因为它正在调用的 RegCap 命令失败了……所以直接调用 RegCap 没有任何帮助.

That did not work out so well... It seems that running RegCap.exe as suggested in that article does not work when running on Vista. Since RegCap is actually run internally by the setup project itself on creating the .msi, this is not terribly surprising. In short, the setup project was almost certainly failing because the RegCap command that it was calling was failing... So calling RegCap directly is of no help.

最重要的是,这只是尝试在 Vista 上创建安装包时的一个错误.或者,也许它是 Visual Studio 2008 和 Vista 的组合,我不确定.尝试相同的方法是在 Windows XP 上运行的 Visual Studio 2005 上创建一个安装项目,绝对没有任何问题.

The bottom line is that this is simply a bug when attempting to create a setup package on Vista. Or, perhaps it is a combination of Visual Studio 2008 and Vista, I'm not sure. Attempting the same exact approach is to create a setup project on Visual Studio 2005 running on Windows XP had absolutely no problems whatsoever.

很可能有一些修复程序可以让它在 Vista 和/或 Visual Studio 2008 上正常运行,但我无法找到它.对我来说更高效的是在 Windows XP 上使用 Visual Studio 2005 构建以生成 COM 注册要求,然后将它们导入到我的 Visual Studio 2008 安装项目中.这些可以通过 regasm 导出为 .REG 文件,对 dll 使用/regfile 开关,对 .tlb 文件使用 RegCap(在 W'XP 上运行!).因为我的 COM 接口不会改变,所以我只需要这样做一次.

There very well may be fixes to get this running right on Vista and/or Visual Studio 2008, but I could not track it down. Much more efficient for me was to build using Visual Studio 2005 on Windows XP to generate the COM registration requirements, and then to import them into my Visual Studio 2008 setup project. These can be exported as .REG files via regasm using a /regfile switch against the dll and using RegCap (running on W'XP!) against the .tlb file. Since my COM interfaces will not be changing, I only have to do this once.

希望 Visual Studio 2008 在 Vista 上运行时的这个问题会在某个时候得到纠正,但如果没有,希望这篇文章对发现自己处于相同情况的其他人有所帮助...

Hopefully this issue in Visual Studio 2008 when running on Vista will be corrected at some point, but if not, hopefully this post will be of some value to someone else who finds him or herself in the same situation...

另见:

如何在自动化服务器列表中安装并注册用VB.NET编写的COM Server for Excel?

-- 迈克

推荐答案

我知道这是很久以前的事了,但我找不到任何明智的答案.我遇到了类似的问题,解决方法是以安装它的同一用户身份运行 Visual Studio.如果我以其他用户身份运行它,除了 COM 注册之外的所有内容都可以正常工作.

I know this was a long time ago, but I can't find any sensible answers. I had a similar problem and the resolution was to run Visual Studio as the same user who installed it. If I run it as a different user everything except the COM registrations works.

这篇关于如何将 COM 公开的 .NET 项目添加到 VB6(或 VBA)引用对话框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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