【发布时间】:2018-04-03 22:04:08
【问题描述】:
我尝试使用此处描述的这种方法访问 C# DLL,但没有成功:
我已经制作了一个 COM DLL (RubyToCSharp.dll):[assembly: ComVisible(true)] 并注册 COM 互操作(如示例中所示):
using System;
using System.Runtime.InteropServices;
using System.IO;
namespace ComLib
{
[ComVisible(true)]
public class LogWriter
{
public void WriteLine(string line)
{
using (var log = new StreamWriter(File.OpenWrite(@"c:\log.file")))
{
log.WriteLine(line);
}
}
}
}
我可以从 c:\Windows\SysWOW64\wscript.exe 使用这个 VB 脚本访问 DLL :
Dim obj
set obj = CreateObject("ComLib.LogWriter")
MsgBox TypeName(obj)
但我无法使用 System32\wscript.exe
访问 DLL当我最终尝试使用以下代码从 Ruby 访问时:
require 'win32ole'
lib = WIN32OLE.new('ComLib.LogWriter')
发生这种情况:
WIN32OLERuntimeError: failed to create WIN32OLE object from `ComLib.LogWriter'
HRESULT error code:0x80040154 Class not registered
即使 DLL 似乎已在 Windows 注册表数据库中注册。
我的设置是:Win10 PC 上的 Ruby v. 2.4 64bit 版本。
有人有一个如何使用 Ruby 访问 C# DLL 的工作示例,或者知道为什么这个示例不起作用?
【问题讨论】: