【问题标题】:Calling Dlls on Ruby (not the Windows API)在 Ruby 上调用 Dll(不是 Windows API)
【发布时间】:2011-04-17 23:00:38
【问题描述】:

我在一个无法加载 C 扩展的 Ruby 环境中,只能加载纯 ruby​​ 代码。我不能使用 RubyInline、FFI 或 Win32OLE,只有一种加载外部代码的方法:Win32API。但是如何编译 ruby​​ 可能需要的 C++ 代码呢?我尝试使用这些代码,但出现错误:

test.cpp

static int add(int a, int b) // I tried without static too
{
  return a + b;
}

编译

g++ --shared test.cpp -o test.dll

main.rb

Win32API.new('test.dll', 'add', 'II', 'I').call(1, 2) # => should return 3

错误信息

RunTimeError
GetProcAddress: add or addA

版本:

Ruby 1.8.1
GCC 4.5.2 (tdm-1)

【问题讨论】:

    标签: c++ ruby winapi


    【解决方案1】:

    您需要使用 .DEF 文件。请参阅我对此的回答 question

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-06
      • 1970-01-01
      • 1970-01-01
      • 2010-10-10
      • 1970-01-01
      • 2015-02-27
      相关资源
      最近更新 更多