在 VBScript 中访问自定义 .NET DLL
我在 .NET 中编写了一个 DLL,我想在 VBScript 中访问它。 我不想将其添加到程序集目录中。
有没有办法也指向 DLL 并创建它的实例?
I wrote a DLL in .NET and I want to access it in VBScript. I don't want to add it to the assembly directory.
Is there a way to point too the DLL and create an instance of it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
不直接。 您将需要一个 COM 可调用包装器来连接您从 COM(以及 VBScript)调用的任何 .NET 库。 因此,您应该直接为 DLL 创建 CCW,也可以为代理 DLL 创建 CCW,该代理 DLL 提供加载 .NET DLL 的通用方法,并为您提供调用组件上的实际方法并返回结果的方法。 真的一点也不干净。 所以,总的来说,答案是否定的。
Not directly. You'll need a COM Callable Wrapper to any .NET library you'll calling from COM (and hence, VBScript). Therefore, you should either directly create a CCW to the DLL or you can create a CCW for a proxy DLL which provides generic methods to load a .NET DLL and provide methods for you that call the actual methods on the component and return the result. It's really not clean at all. So, in general, the answer is no.
如果有人需要调试/单步调试仅从 VBScript 调用的 .Net dll:
在 .Net dll 项目调试设置屏幕上,通过浏览到 wscript.exe 程序(位于 \
在“命令行参数”中,设置 VBScript 文件的文件名和路径位置 (C:\Test\myTest.vbs)。 确保 vbs 文件和 dll 文件位于同一位置。
最后,在.Net项目DLL源代码中设置断点并点击“开始调试”
In case someone needs to debug/step-into the .Net dll that's called from VBScript only:
On the .Net dll project debug setup screen, set the "start external program" by browsing to the wscript.exe program (located in C:\WINDOWS\system32\wscript.exe).
On the "Command Line Arguments", set the file name and path location of the VBScript file (C:\Test\myTest.vbs). Make sure the vbs file and dll file are in the same location.
Finally, in the .Net project DLL source code just set the break point and hit the "start debug"
您可以通过指定
使用regasm实用程序注册该.NET dll >/codebase
参数。 不鼓励将此参数与未签名的程序集一起使用,但当您无法将程序集放入 GAC 时,它会起作用。请注意,执行此操作后不应更改 .dll 的路径,因为它会将此路径插入到 Windows 注册表中。
You can register that .NET dll with regasm utility by specifying
/codebase
parameter. This parameter is not encouraged to use with unsigned assemblies but it works when you can not put your assembly into GAC.Please note that you should not change your .dll's path after this operation since it inserts this path into the Windows registry.
huseyint 的答案是关于钱,但是,我想补充一点。 这是我针对这个问题使用的一些示例代码,也许它可以加快您的速度...
我在 dll 中包含了一个 IsAlive 方法......
并且可以使用语法检查它是否正确注册:
希望这有帮助某人...
huseyint's answer was on the money, however, I wanted to add a little to it. Here is some sample code I used for this very issue, perhaps it can speed you along...
I had included an IsAlive method in the dll...
...and could check that it registered correctly using the syntax:
Hope this helps someone...
我只需要自己做这件事,我的发现是:
使类型对 COM 可见:
确保您在程序集中进行了以下设置 - 通常在 AssemblyInfo.cs 中
构建 DLL 后,从 SDK 命令行运行:
这应该响应:
<块引用>
类型注册成功
如果你得到
<块引用>
RegAsm:警告 RA0000:未注册任何类型
那么您需要设置
ComVisible
或没有公共非静态类型。来自 PowerShell
来自 vbs
I just had to do this myself, my findings were:
Making types visible to COM:
Ensure you have the following set on your assembly - typically in AssemblyInfo.cs
After building your DLL, from SDK command line run:
This should respond:
If you get
then you need to set
ComVisible
or have no public, non-static types.From PowerShell
From vbs