Calling Dlls on Ruby (not the Windows API)
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
精彩评论