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

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

问题描述

根据异常文章由Phil Wilson构建和部署.NET COM程序集

在.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 Interop方面的工作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...

Mike

编辑/更新

回答jpoh的问题我使用的是/ codebase开关,我使用的是.msi安装程序包,而不是明确使用RegAsm。组件正确注册,这可以由HKCR\CLSID {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 HKCR\CLSID{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文件应该为我的类基于HKCR\Interface {myInterfaceGUID}的接口放置一些注册表项,但这不会发生。奇怪的是,这种缺乏注册似乎并不影响dll的功能,除了它在VB6和VBA的引用对话框中的发现之外。

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 HKCR\Interface{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,注册属性设置为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:

VS2008安装项目中的COM typelib注册问题

这里有一些手动修复:

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

我还没有尝试修复,但明天我会报告,如果这样做解决了。

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

更新#4

没有这么好的工作...似乎运行RegCap.exe在该文章中建议在Vista上运行时不起作用。由于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文件,使用/ regfile开关对dll,并对.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.

希望在Vista上运行的Visual Studio 2008中的这个问题将在某些时候得到纠正,但如果没有,希望这篇文章对于在同一情况下找到自己的人来说是有价值的。

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

另请参见: strong>

See Also:

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

- Mike

推荐答案

我知道这是很久以前,找不到任何明智的答案。我有一个类似的问题,解决方案是运行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天全站免登陆