创建一个简单的c#dll并从ruby访问它 [英] Creating a simple c# dll and access it from ruby

查看:177
本文介绍了创建一个简单的c#dll并从ruby访问它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让我的第一个c#dll。
我希望能够使用win32API从ruby中调用它的方法/函数。
我已经做了这个dll:

  using System; 
使用System.Collections.Generic;
使用System.Linq;
使用System.Text;

命名空间ClassLibrary1
{
public class Class1
{

public int PropA = 10;

public void Multiply(Int32 myFactor)
{
PropA * = myFactor;

}
}
}

我编译它与Visual Studio 2010,并得到了我的ClassLibrary1.dll文件。



现在对于ruby部分我尝试这样:

  f =c:/path_to_file/ClassLibrary1.dll
mult = Win32API.new(f,Multiply,[I],I)

但是,我收到以下错误:

 错误:#< RuntimeError:(eval):0:在'initialize'中:GetProcAddress:乘法或乘法A 

说实话,我从来没有创建过dll,也没有c#的经验。我只是想开始我以前通过win32API使用了很多dll,之前(user32主要是)。



我想我的DLL不行吗



请问,

解决方案

不做任何额外的操作,创建的DLL是一个Assmebly意图在.Net运行时运行(CLR)。



您可以通过Com将其公开,如相关问题所述:可以Ruby导入一个.NET dll吗?哪个


I'm trying to make my first c# dll. I want to be able to call it's methods/functions from ruby with win32API. I have made this dll:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ClassLibrary1
{
    public class Class1
    {

        public int PropA = 10;

        public void Multiply(Int32 myFactor)
        {
            PropA *= myFactor;

        }
    }
}

I compiled it with Visual Studio 2010 and got my ClassLibrary1.dll file.

Now for the ruby part i tried this:

f = "c:/path_to_file/ClassLibrary1.dll"
mult = Win32API.new(f,"Multiply",["I"],"I")

But, i get the following error:

Error: #<RuntimeError: (eval):0:in `initialize': GetProcAddress: Multiply or MultiplyA

To be honest, I never created a dll, nor do I have experience with c#. I just wanted to get started. I have used many dll's with Ruby via win32API before (user32 mostly).

I guess my dll is not ok?

Regards,

解决方案

Without doing anything extra, the DLL created is an Assmebly intended to be run inside the .Net runtime (the CLR).

You can expose it through Com as described in the related question: Can Ruby import a .NET dll? which

这篇关于创建一个简单的c#dll并从ruby访问它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆