开发者

Calling Dlls on Ruby (not the Windows API)

开发者 https://www.devze.com 2023-02-26 01:48 出处:网络
I\'m at a Ruby enviroment where I can\'t load C extensions, just pure-ruby code. I can\'t use RubyInline, FFI or Win32OLE, only one way to load an external code: Win32API. But how can I compile a C++

I'm at a Ruby enviroment where I can't load C extensions, just pure-ruby code. I can't use RubyInline, FFI or Win32OLE, only one way to load an external code: Win32API. But how can I compile a C++ code that can be required 开发者_StackOverflowby the ruby? I tried with these codes, but raised an error:

test.cpp

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

compile

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

main.rb

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

error message

RunTimeError
GetProcAddress: add or addA

versions:

Ruby 1.8.1
GCC 4.5.2 (tdm-1)


You need to use a .DEF file. See my answer to this question

0

精彩评论

暂无评论...
验证码 换一张
取 消