[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

WIN32API

Wolfgang

5/30/2005 8:50:00 AM

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
8 Answers

Brian Schröder

5/30/2005 9:24:00 AM

0

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


--
http://ruby.brian-sch...

Stringed instrument chords: http://chordlist.brian-sch...


Wolfgang

5/30/2005 11:34:00 AM

0

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

Dave Burt

5/30/2005 12:37:00 PM

0

"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':

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

Cheers,
Dave


Park Heesob

5/30/2005 1:09:00 PM

0

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








Wolfgang

5/30/2005 1:49:00 PM

0

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

Wolfgang

5/30/2005 2:29:00 PM

0

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

Wolfgang

Wolfgang

5/30/2005 2:57:00 PM

0

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

Dave Burt

5/30/2005 10:01:00 PM

0

"Park Heesob" <phasis@bcline.com> wrote...
> Hi,
> ----- Original Message -----
> From: "Dave Burt" <dave@burt.id.au>
>>
>> "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.
>
> ...

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 :)
Cheers,
Dave