在Ruby上调用dll(不是Windows API)

Calling Dlls on Ruby (not the Windows API)

本文关键字:不是 Windows API dll Ruby 调用      更新时间:2023-10-16

我在一个Ruby环境中,我不能加载C扩展,只有纯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)

您需要使用. def文件。请看我对这个问题的回答

相关文章: