Guilherme Bernal
Guilherme Bernal

Reputation: 8293

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 by 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)

Upvotes: 0

Views: 923

Answers (1)

John
John

Reputation: 5635

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

Upvotes: 2

Related Questions