Forum: Ruby Very new to Ruby--needs help

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
47e8d8a46c78162a28fb85af179062ef?d=identicon&s=25 Beginner (Guest)
on 2005-12-19 22:30
(Received via mailing list)
Dear Ruby Gurus,

I would like to load a *.lib file into my *.rb file. How to do that. I
did mentioned the path but was not successful. I did this:

load (or require) "PATH name:*.lib"

thx,
Mankan
Fe9b2d0628c0943af374b2fe5b320a82?d=identicon&s=25 Eero Saynatkari (rue)
on 2005-12-20 00:03
Beginner wrote:
> Dear Ruby Gurus,
>
> I would like to load a *.lib file into my *.rb file. How to do that. I
> did mentioned the path but was not successful. I did this:
>
> load (or require) "PATH name:*.lib"

What is in the .lib file?

If it is ruby code (in which case you should just
change it to .rb anyway:),

  require "#{path}/foobar.lib"

Should work fine.

If it is object code, I believe ruby can only load
.so (and, I assume, .dll) files so you may need to
extract the shared library.

If it is just plain text or something, you would
want to use File.open(filename) {|f| do_something_with f }.

Please clarify a bit and I am sure we can help you
get it working right!

> thx,
> Mankan


E
47e8d8a46c78162a28fb85af179062ef?d=identicon&s=25 Beginner (Guest)
on 2005-12-20 14:30
(Received via mailing list)
Dear Eero,

Thank you very much. it is a low-level APIs named power32.lib and I
would like to call this APIs from ruby to find the hardware parameters
like number of boards etc.

Hence I am looking for loading this power32.lib file and then call the
low-level API from Ruby.

Pls do let me know if the question is still not clear.

thx in advance,
Mankan
47e8d8a46c78162a28fb85af179062ef?d=identicon&s=25 Beginner (Guest)
on 2005-12-20 15:24
(Received via mailing list)
Dear Eero,

I am not able to load even .dll, this is what I did:

require "C:\\WINDOWS\\SYSTEM32\\abc.dll"

I am doing anything wrong. The .dll does exist in the directory, I get
the erro, "the specified procedure could not be found".(loadError)

thx,
Mankan
37a3c73ffbf864e4b28f7f2384ee12ce?d=identicon&s=25 Timothy Hunter (tim-hunter)
on 2005-12-20 15:39
(Received via mailing list)
Beginner wrote:
> Mankan
>
The "require" statement loads Ruby extensions, either those written in
pure Ruby or those written in C using the Ruby extension API. So you
can't use it to interface to an arbitrary .dll or .lib file.

There is a Ruby library that allows you to call functions in .dll files,
though. Check out the Win32API class:
http://www.rubycentral.com/book/lib_windows.html

You might also learn more about the Win32API library by searching
through old postings to this list. Search for "Win32API".

Welcome to Ruby!
2c51fec8183a5d21c4e11b430beabb47?d=identicon&s=25 Patrick Hurley (Guest)
on 2005-12-20 15:57
(Received via mailing list)
On 12/20/05, Beginner <smankan@ueidaq.com> wrote:
> I am not able to load even .dll, this is what I did:
>
> require "C:\\WINDOWS\\SYSTEM32\\abc.dll"

Is abc.dll the dll associated with power32.lib? Or just an example. I
am unfamiliar (as is at least a cursory Google :-) with this
particular library. Without a specific API document, I doubt we can
provide you with the level of detail you will need at this stage in
your programming career.

From a high level there are two ways normally used to access external
libraries from within Ruby:

1. Create an extension -- this requires a certain amount of C
programming either by hand or using something like SWIG.

2. Or using DL (http://ttsky.net/ruby/ruby-dl.html)

If you can provide a specific API for the library you may get some
additional help (even more so if the library in question is free/open
source).

Good Luck
47e8d8a46c78162a28fb85af179062ef?d=identicon&s=25 Beginner (Guest)
on 2005-12-20 16:48
(Received via mailing list)
Thank you Timothy and Patrick, I got the answer to what I am looking
for.

-Mankna
This topic is locked and can not be replied to.