使用 VS 2008 (vb.net),我需要创建一个可以在经典 ASP 中使用 CreateObject 使用的对象
我对 VB.net 很陌生。 我以前用VB6编写过这些对象。 我只是迷失在 VB.net 中,但是(又踢又尖叫)我必须学习如何做到这一点。 我已经在谷歌上搜索了几个小时,只取得了很小的进展。 任何人都可以发布一个链接来解释如何从头到尾执行此操作吗?
我已经成功编写了类对象,但我不知道如何注册它以及 CreateObject("Name1.Name2") 中的 name1 和 name2 来自哪里。
Regsrv32 将不起作用。 它显示“未找到入口点”并且不会注册它。 另外,我无法将其放入 Assemblies 目录中。 我读过一些关于人们使用的 regasm 命令的内容,但我似乎也无法使其工作。
预先感谢您的任何帮助。
I am very new to VB.net. I have written these objects in VB6 before. I'm just lost in VB.net, but (kicking and screaming) I have to learn how to do this. I've been googling for hours with only minor steps forward. Can anyone post a link that explains start to finish how to do this?
I have managed to write the class object, What I can not tell is how to register it and where the name1 and name2 in the CreateObject("Name1.Name2") come from.
Regsrv32 will not work. It says "Entry Point not found" and will not register it. Also, I can not drop it into the Assemblies directory. I read something about a regasm command one uses, but I can't seem to make this work either.
Thanks in advance for any assistance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我假设您并不是要编写 COM DLL,而是要编写一个完整的项目,该项目调用各种子程序集,例如 VB6 EXE 调用 ActiveX DLL。 如果你能更具体地说明你正在尝试做什么,那会对我有更好的帮助。
关于 VB.NET 与 VB6 的几点。
1) 对于仅限 .NET 的项目,无需注册。 如果 EXE 或 DLL 引用另一个 .NET DLL,唯一的要求是 DLL 存在于父目录中。
2) 您只能通过在 GAC 中注册 .NET 程序集来为 .NET 应用程序进行 COM 样式注册。 然而,这样做有几个要求。 在 .NET GAC 上搜索一下,它会给您有关如何执行此操作的独家新闻。
3) 您可以将 .NET 程序集设置为使用 COM,在这种情况下,它将按照 COM 规则进行操作,包括使用 regsvr 进行注册。
您会发现,对于仅 .NET 的项目,#2 或#3 仅在极少数情况下出现。 #1 将适用于 90% 的 DLL 程序集。 这取决于您的项目。
CreateObject 的常见用途是允许插件或可安装库。 .NET 通过反射 API 处理此问题。 使用反射 API,您可以查看目录,浏览每个 .NET DLL 并查看它们的内容,并根据找到的内容创建对象。 搜索 .NET Reflection 来阅读相关内容。
如果您的项目仅是 .NET,那么我建议您创建一个由主程序集和定义您正在创建的对象的接口的各个子程序集引用的程序集。 当您使用反射 API 并确定对象类型时,您可以将其分配给该接口的变量,并使用智能感知和其他辅助工具对其进行正常编码。
如果您有旧的 COM ActiveX 控件或 DLL,.NET 将生成一个包装类,将 ActiveX 对象公开给 .NET。 我会花一些时间学习 .NET 如何做到这一点。 我所做的就是创建一个虚拟项目并让 .NET 引用我需要的 ActiveX 内容。 然后,我找到它制作的包装器项目和 DLL,并将它们移动到中心区域。 这就是为什么当我使用相同的 ActiveX 内容处理后续项目时,我知道所有包装器在哪里。
I am going to assume you are not trying to write a COM DLL but rather a complete project that call various sub assemblies like a VB6 EXE call a ActiveX DLL. If you can be more specific about what you are trying to do it would help me better.
Several points about VB.NET versus VB6.
1) For .NET only projects there is no registration. If a EXE or DLL references another .NET DLL the only requirement is that the DLLs be present in the parent's directory.
2) You can do a COM style registration for .NET apps only by registering the .NET assembly in the GAC. However there are several requirements for doing this. Do a search on the .NET GAC and it will give you the scoop on how to do this.
3) You can setup the .NET assembly to use COM in which case it will operate by the rules of COM including registration with regsvr.
You will find for .NET only project that #2, or #3 only come in rare instances. #1 will apply for 90% of your DLL assemblies. Of This is dependent on your project.
A common use for CreateObject is allow for plug-ins or installable libraries. .NET handles this through the Reflection API. With the reflection API you can look in a directory, go through each .NET DLL and see what them and create objects from what you find. Search for .NET Reflection to read up on this.
If your project is .NET only then I recommend that you create a Assembly that is reference by both the master assembly and the individual sub assembly that define the interfaces of the objects you are creating. This when you use the reflection API and determine the Object type you can assign it to a variable of that interface and code it noramlly with intellisense and other aids.
if you have old COM ActiveX Controls or DLLs .NET will generate a wrapper class that exposes the ActiveX Objects to .NET. I would spend some time learning how .NET does this. What I do create a dummy project and have .NET reference the ActiveX stuff I need. I then find the wrapper projects and DLL it made and move them into a central area. That why when I work on subsquent projects using the same ActiveX stuff I know where all the wrappers are.
您必须转到类库属性并选择“注册 COM 互操作”选项。 这将使您的程序集可用于 COM。
You have to go to your class library properties and select the option "Register for COM interop". This will make your assembly available to COM.
您想要为您的应用创建一个所谓的 COM Callable Wrapper(又名 CCW) .NET 组件。 这基本上需要使用一些 GUID 设置一些 COM 接口,并在项目属性中启用“注册 COM 互操作”(如上所述)或使用 regasm.exe。
You want to create what's called a COM Callable Wrapper (aka CCW) for your .NET component. This basically entails setting up some COM interfaces with some GUIDs and either enabling "Register for COM Interop" in the project properties (as mentioned) or using regasm.exe.