Win32api

Hello,

I started programming not too long ago, so please excuse this question if it is too silly.

I wrote a small dll in fortran wich gives back a number. when I call this dll from ruby I get this number only when it is defined as integer in fortran. When I change it to real I get "1065353216" when the dll should give back 1.0

What do I make wrong?

Thanks

Wolfgang

It seems to me that you are reading the return value of the dll
function as an integer, while a floating point number is returned. How
are you're interfaces defined. Could you post some code?

best regards,

Brian

···

On 30/05/05, Wolfgang <wollez@gmx.net> wrote:

Hello,

I started programming not too long ago, so please excuse this question
if it is too silly.

I wrote a small dll in fortran wich gives back a number. when I call
this dll from ruby I get this number only when it is defined as integer
in fortran. When I change it to real I get "1065353216" when the dll
should give back 1.0

What do I make wrong?

Thanks

Wolfgang

--
http://ruby.brian-schroeder.de/

Stringed instrument chords: http://chordlist.brian-schroeder.de/

Hello Brian,

up to now I only have this in ruby:

require 'Win32API'
win = Win32API.new("dlltest.dll","DLL_WOOD",,'L')
somevalues = win.call()
print somevalues

the self made dll should return at the moment a fixed value (for testing). I tried this with an integer, than it works. As soon I define the variable in fortran as real, I get this nice numbers.

Wolfgang

Brian Schröder wrote:

···

On 30/05/05, Wolfgang <wollez@gmx.net> wrote:

Hello,

I started programming not too long ago, so please excuse this question
if it is too silly.

I wrote a small dll in fortran wich gives back a number. when I call
this dll from ruby I get this number only when it is defined as integer
in fortran. When I change it to real I get "1065353216" when the dll
should give back 1.0

What do I make wrong?

Thanks

Wolfgang

It seems to me that you are reading the return value of the dll
function as an integer, while a floating point number is returned. How
are you're interfaces defined. Could you post some code?

best regards,

Brian

Hi!

The last parameter to Win32API.new is the type of the return value. If your
DLL function returns a long integer, 'L' is correct. If you change the DLL
so that the function returns a float or a double, you will have to change
that last parameter to 'F' or 'D':

# function returns a double
win = Win32API.new("dlltest.dll","DLL_WOOD",,'D')

Cheers,
Dave

···

"Wolfgang" <wollez@gmx.net> wrote:

Hello Brian,

up to now I only have this in ruby:

require 'Win32API'
win = Win32API.new("dlltest.dll","DLL_WOOD",,'L')
somevalues = win.call()
print somevalues

the self made dll should return at the moment a fixed value (for testing).
I tried this with an integer, than it works. As soon I define the variable
in fortran as real, I get this nice numbers.

Wolfgang

Hi,

···

----- Original Message -----
From: "Dave Burt" <dave@burt.id.au>
Newsgroups: comp.lang.ruby
To: "ruby-talk ML" <ruby-talk@ruby-lang.org>
Sent: Monday, May 30, 2005 9:40 PM
Subject: Re: WIN32API

"Wolfgang" <wollez@gmx.net> wrote:

Hello Brian,

up to now I only have this in ruby:

require 'Win32API'
win = Win32API.new("dlltest.dll","DLL_WOOD",,'L')
somevalues = win.call()
print somevalues

the self made dll should return at the moment a fixed value (for
testing).
I tried this with an integer, than it works. As soon I define the
variable
in fortran as real, I get this nice numbers.

Wolfgang

Hi!

The last parameter to Win32API.new is the type of the return value. If
your
DLL function returns a long integer, 'L' is correct. If you change the DLL
so that the function returns a float or a double, you will have to change
that last parameter to 'F' or 'D':

As far as I know, You can't use 'F' or 'D' paramenter in Win32API.

This should be work for you:

require 'Win32API'
win = Win32API.new("dlltest.dll","DLL_WOOD",,'L')
somevalues = [win.call()].pack("L").unpack("f")[0]
print somevalues

Regards,

Park Heesob

Thanks for your help, but it is still not running. I think the fault is in my Fortran code.

Wolfgang

Park Heesob wrote:

···

Hi,
----- Original Message ----- From: "Dave Burt" <dave@burt.id.au>
Newsgroups: comp.lang.ruby
To: "ruby-talk ML" <ruby-talk@ruby-lang.org>
Sent: Monday, May 30, 2005 9:40 PM
Subject: Re: WIN32API

"Wolfgang" <wollez@gmx.net> wrote:

Hello Brian,

up to now I only have this in ruby:

require 'Win32API'
win = Win32API.new("dlltest.dll","DLL_WOOD",,'L')
somevalues = win.call()
print somevalues

the self made dll should return at the moment a fixed value (for testing).
I tried this with an integer, than it works. As soon I define the variable
in fortran as real, I get this nice numbers.

Wolfgang

Hi!

The last parameter to Win32API.new is the type of the return value. If your
DLL function returns a long integer, 'L' is correct. If you change the DLL
so that the function returns a float or a double, you will have to change
that last parameter to 'F' or 'D':

As far as I know, You can't use 'F' or 'D' paramenter in Win32API.

This should be work for you:

require 'Win32API'
win = Win32API.new("dlltest.dll","DLL_WOOD",,'L')
somevalues = [win.call()].pack("L").unpack("f")[0]
print somevalues

Regards,

Park Heesob

"Park Heesob" <phasis@bcline.com> wrote...

Hi,
From: "Dave Burt" <dave@burt.id.au>

Hello Brian,

up to now I only have this in ruby:

require 'Win32API'
win = Win32API.new("dlltest.dll","DLL_WOOD",,'L')
somevalues = win.call()
print somevalues

the self made dll should return at the moment a fixed value (for
testing).
I tried this with an integer, than it works. As soon I define the
variable
in fortran as real, I get this nice numbers.

Wolfgang

Hi!

The last parameter to Win32API.new is the type of the return value. If
your
DLL function returns a long integer, 'L' is correct. If you change the
DLL
so that the function returns a float or a double, you will have to change
that last parameter to 'F' or 'D':

As far as I know, You can't use 'F' or 'D' paramenter in Win32API.

...

You're right. I was thinking about Ruby/DL. Maybe, Wolfgang, you could use
that instead:

# untested code
require 'dl'
dl = DL.dlopen = "dlltest.dll"
func = dl["DLL_WOOD", "D"]
somevalues = func.call
p somevalues

Hope this helps more that my last post :slight_smile:
Cheers,
Dave

···

----- Original Message -----

"Wolfgang" <wollez@gmx.net> wrote:

I found the fault! I can not use a fortran subroutine! With a function it works perfect.

Wolfgang

Has anyone an idea how I can get data in double precision?

win = Win32API.new("dlltest.dll","DLL_WOOD",[],'L')

I assume the 'L' here limits the precision

Wolfgang