From: WATANABE Hirofumi Date: 2003-08-11T19:14:41+09:00 Subject: Re: win32api calling with doubles Hi, ROTH Jakub writes: > How does one declare and external function (in a DLL) for use with Ruby > which requires doubles as parameters and likewise returns double as a > result? Is there any good detailed doc/info on the web on this? Win32API does not support double. > I have a C fct declared as > > double jadd2( double a, double b ) > > and export it from a DLL it gets compiled into. I want to call it from Ruby. > Import it into Ruby as: > > jadd2 = Win32API.new('jadd.dll', 'jadd2', 'dd', 'd') > > and call as > > p jadd2.Call( 1.3, 2.4 ) > > the error is "in `Call': Wrong number of parameters: expected 0, got 2. > (RuntimeError)" Use Ruby/DL: % cat foo.c double foo(double a, double b) { return a + b; } % gcc -mno-cygwin -shared foo.c -o foo.dll % cat footest.rb require 'dl/import' module Foo extend DL::Importable dlload "foo" extern "double foo(double, double)" end p Foo.foo(1.1, 2.2) % ruby footest.rb 3.3 -- eban