From: di vi on
Hi,

I have a C++ code converted into a windows Dll.I want to use Ruby /DL to
invoke the functions in the DLL.

Here are the function prototypes:
C++ code
[code]
// MathFuncsDll.h

namespace MathFuncs
{
class MyMathFuncs
{
public:
// Returns a + b
static __declspec(dllexport) double Add(double a, double b);

// Returns a - b
static __declspec(dllexport) double Subtract(double a, double
b);

// Returns a * b
static __declspec(dllexport) double Multiply(double a, double
b);

// Returns a / b
// Throws DivideByZeroException if b is 0
static __declspec(dllexport) double Divide(double a, double b);
};
}
[/code]

Ruby code
[code]
require 'dl/import'
module MATHFUN
extend DL::Importable
dlload "math funcs.dll"
extern "double Add(double a, double b)"
#extern "int strlen(const char *)"
end
MATHFUN.Add(5,4)
[/code]

Gives me an error saying undefined symbol.
--
Posted via http://www.ruby-forum.com/.

From: Aaron Patterson on
On Thu, Feb 11, 2010 at 12:10:20AM +0900, di vi wrote:
> Hi,
>
> I have a C++ code converted into a windows Dll.I want to use Ruby /DL to
> invoke the functions in the DLL.

C++ code? Unless you know how to munge your functions the same way your
compiler does, I don't think you're going to get very far.

--
Aaron Patterson
http://tenderlovemaking.com/

From: Albert Schlef on
di vi wrote:
> Hi,
>
> I have a C++ code converted into a windows Dll.
[...]
> require 'dl/import'
> module MATHFUN
> extend DL::Importable
> dlload "math funcs.dll"
> extern "double Add(double a, double b)"

There are some utility programs that let you look into a library and see
the symbols exposed. This way you see how the compiler mangled them. For
example, in linux you can do `nm -D library.so`.

Or create some 'extern "C"' wrapper functions for your methods.
--
Posted via http://www.ruby-forum.com/.

From: Albert Schlef on
Albert Schlef wrote:
> There are some utility programs that let you look into a library and see
> the symbols exposed. This way you see how the compiler mangled them.

(It goes without saying that if you distribute your source code,
somebody may use a compiler which mangles the names differently and your
ruby/dl won't see them anymore.)

--
Posted via http://www.ruby-forum.com/.

From: di vi on
Albert Schlef wrote:
> Albert Schlef wrote:
>> There are some utility programs that let you look into a library and see
>> the symbols exposed. This way you see how the compiler mangled them.
>
> (It goes without saying that if you distribute your source code,
> somebody may use a compiler which mangles the names differently and your
> ruby/dl won't see them anymore.)

I used PE explorer and saw the dill in disassembler.Attached is the
picture showing its names.Please advice.

Attachments:
http://www.ruby-forum.com/attachment/4469/dll_debug1.JPG

--
Posted via http://www.ruby-forum.com/.