问题描述
我有一个用 .Net 编写的类库,我想将它提供给 VB6/VBA.我试过的没有用(显然我在问这个问题).这是我所做的:
- 我在 Visual Studio 2010 Express 中创建了一个类库项目并将代码放入一个类模块中.
- 我打开项目属性并转到程序集信息"并选中使 COM 可见".
- 我转到高级编译"选项并针对 .Net 2.0(这是非常简单的代码).
- 然后我删除了所有对系统"的引用.
- 我构建了项目(没有警告或错误)并将 DLL 从 Bin 文件夹复制到 C:WindowsSystem32
- 我运行 RegSvr32 注册 DLL 并得到错误:
<块引用>
模块MyDll.dll"已加载,但未找到入口点 DLLRegisterServer.
确保MyDll.dll 是有效的 DLL 或 OCX 文件,然后重试.
显然我的第一次尝试有点天真.有人可以提供指导吗?
第 6 步错误.具有 [ComVisible] 类型的 .NET 程序集在 Regasm.exe 中注册.如果您不想将 DLL 安装到 GAC 中,请使用/codebase 命令行选项./tlb 命令行选项创建类型库,您可以在 VB6 项目中使用它.
I have a class library written in .Net that I would like to make available to VB6/VBA. What I tried did not work (obviously as I am asking this question). Here is what I did:
- I Created a Class Library Project in Visual Studio 2010 Express and put the code in a Class Module.
- I opened the project properties and went to "Assembly Information" and checked "Make COM Visible".
- I went to "Advanced Compile" options and targeted .Net 2.0 (it's very simple code).
- I then removed all references expect for "System".
- I built the project (no warnings or errors) and copied the DLL out of the Bin folder into C:WindowsSystem32
- I ran RegSvr32 to register the DLL and got the error:
The module "MyDll.dll" was loaded but the entry-point DLLRegisterServer was not found.
Make sure that "MyDll.dll is a valid DLL or OCX file and then try again.
Clearly my first attempt was a bit naive. Could someone offer guidance?
Step #6 is wrong. .NET assemblies with [ComVisible] types are registered with Regasm.exe. Use the /codebase command line option if you don't want to install the DLL into the GAC. The /tlb command line option creates the type library, you can use that in your VB6 project.
这篇关于使 DLL COM 可访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!