I have tried to access a C# DLL using this approach described here without success:
I have made a COM DLL (RubyToCSharp.dll) with: [assembly: ComVisible(true)]
and Register for COM interop (like in the example):
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);
}
}
}
}
I am able to access the DLL using this VB script from c:\Windows\SysWOW64\wscript.exe :
Dim obj
set obj = CreateObject("ComLib.LogWriter")
MsgBox TypeName(obj)
but I am not able to access the DLL using System32\wscript.exe
When I finally try to access from Ruby with the following code:
require 'win32ole'
lib = WIN32OLE.new('ComLib.LogWriter')
This happens :
WIN32OLERuntimeError: failed to create WIN32OLE object from `ComLib.LogWriter'
HRESULT error code:0x80040154 Class not registered
even though the DLL seems to be registered in Windows Registry database.
My setup is: Ruby v. 2.4 64bit version on Win10 PC.
Do someone have a working example how to access a C# DLL using Ruby or have any idea why this example does not work?
You are using a 32 bit version of wscript and a 64 bit version of Ruby. This rather implies that, since the COM server can be found from wscript but not Ruby, your COM server is 32 bit in processes COM server.
You cannot mix 32 and 64 bit code in a single process. Either use a 32 bit version of Ruby, or compile and register a 64 bit version of your COM server.
User contributions licensed under CC BY-SA 3.0