使 DLL COM 可访问
我有一个用 .Net 编写的类库,我想将其提供给 VB6/VBA。我尝试过的方法不起作用(显然我在问这个问题)。我所做的如下:
- 我在 Visual Studio 2010 Express 中创建了一个类库项目,并将代码放入类模块中。
- 我打开项目属性并转到“程序集信息”并选中“使 COM 可见”。
- 我进入“高级编译”选项并瞄准.Net 2.0(这是非常简单的代码)。
- 然后我删除了所有对“系统”的引用。
- 我构建了该项目(没有警告或错误)并将 DLL 从 Bin 文件夹复制到 C:\Windows\System32\
- 我运行 RegSvr32 来注册 DLL 并收到错误:
模块“MyDll.dll”已加载,但未找到入口点 DLLRegisterServer。
确保“MyDll.dll 是有效的 DLL 或 OCX 文件,然后重试。
显然我的第一次尝试有点天真。有人可以提供指导吗?
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:\Windows\System32\
- 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
步骤#6 是错误的。具有 [ComVisible] 类型的 .NET 程序集使用 Regasm.exe 注册。如果您不想将 DLL 安装到 GAC 中,请使用 /codebase 命令行选项。 /tlb 命令行选项创建类型库,您可以在 VB6 项目中使用它。
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.
您需要为接口定义 GUID,并标记哪些类实现哪些接口才能启动。 MSDN 有一个入门指南。您不需要运行 RegSvr32,但需要将 DLL 放置在 的某个位置应用程序可以在哪里找到它:
此处还提供了整个过程的详细概述。
You'll need to define GUIDs for your interfaces and mark which classes implement which interfaces, to start. MSDN has a getting started guide. You don't need to run RegSvr32, but you do need to put the DLL somewhere where the app can find it:
There is also a good overview of the whole process here.
我相当确定 RegSvr32 只适用于非 .NET DLL。 .NET 程序集存储在全局程序集缓存 (GAC) 中。您必须运行 gacutil.exe。
I am fairly certain RegSvr32 only works on non.NET DLL. .NET assemblies are stored in the Global Assembly Cache (GAC). You have to run the gacutil.exe.
使用 GacUtil 而不是 RegSvr32。 RegSvr 用于使用 VB6 生成的 dll,对于 .NET DLL,您需要使用 GacUtil,因为它被添加到全局程序集缓存中。
Use GacUtil instead of RegSvr32. RegSvr is used for dll's made with VB6 and for the .NET DLL's you need to use GacUtil because it is added to the global assembly cache.