newbie question: Accessiong non-Windows DLL's

R

Rich Maniscalco

Hello,

I am very new to Ruby, as in about 1 week new. General Ruby programming
is going well. However, I am having trouble accessing functions in
non-Windows DLL's. We have custom DLL's used to talk to test equipment.
These DLL's are created in C using Visual C++. They work fine with the
original C program. I'm want to use Ruby scripts that access these
DLL's. The documentation gives examples of accessing Windows libraries,
which worked for me. But my stuff is giving me the "`initialize':
GetProcAddress:" error. I also created a very basic DLL which just
prints "Hello World" and had the same Ruby error.

Is there a pointer to some documentation/code examples I can read? Or
can someone tell me what I'm doing wrong?

I'm using Ruby 1.8.6 on Windows XP and Cygwin bash shell.

Thanks,

Rich
 
P

Philliam Auriemma

Hello,

I am very new to Ruby, as in about 1 week new.  General Ruby programming
is going well.  However, I am having trouble accessing functions in
non-Windows DLL's.  We have custom DLL's used to talk to test equipment..
These DLL's are created in C using Visual C++.  They work fine with the
original C program.  I'm want to use Ruby scripts that access these
DLL's.  The documentation gives examples of accessing Windows libraries,
which worked for me.  But my stuff is giving me the "`initialize':
GetProcAddress:" error.  I also created a very basic DLL which just
prints "Hello World" and had the same Ruby error.

Is there a pointer to some documentation/code examples I can read?  Or
can someone tell me what I'm doing wrong?

I'm using Ruby 1.8.6 on Windows XP and Cygwin bash shell.

Thanks,

  Rich

I think you may be able to use the Win32API module for that.

http://www.rubytips.org/2008/05/13/accessing-windows-api-from-ruby-using-win32api-library/
 
R

Roger Pack

which worked for me. But my stuff is giving me the "`initialize':
GetProcAddress:" error. I also created a very basic DLL which just
prints "Hello World" and had the same Ruby error.
I'm using Ruby 1.8.6 on Windows XP and Cygwin bash shell.

You might get some traction by using a ruby compiled with the same
compiler that made your dll's, like the old one click installer for MSVC
compiled dll.
-r
 
P

Philliam Auriemma

Hi Philliam,

Thanks for the info.  I cut-n-pasted those examples and they work for
me.  However, I am trying to call NON Windows API functions.  Any tips
for that?

Thanks,

  Rich

You should be able to make a DLL and have it export the correct
symbols for your functions, and put the DLL file in C:/WINDOWS/
system32 (may be just C:/WINDOWS/ or C:/WINDOWS/system/, can't
remember) and you can use your own DLL the same way. I'm not sure how
to do it any other way without making your own ruby extension, which I
found impossible.
 
R

Rich Maniscalco

Roger said:
You might get some traction by using a ruby compiled with the same
compiler that made your dll's, like the old one click installer for MSVC
compiled dll.
-r

Hi Roger,

Thanks for the info. I had installed Ruby using "Ruby 1.8.6 One-Click
Installer" from ruby-lang.org. Are you suggesting I rebuild both Ruby
and my DLL's? Just checking for clarity.

Thanks,

Rich
 
R

Rich Maniscalco

Rich said:
Hi Roger,

Thanks for the info. I had installed Ruby using "Ruby 1.8.6 One-Click
Installer" from ruby-lang.org. Are you suggesting I rebuild both Ruby
and my DLL's? Just checking for clarity.

Thanks,

Rich



BTW, my current VC++ is " Microsoft Visual C++ 2008 Express Edition
version 9". Ruby is compiled with 6.0. Will that matter?

Rich
 
R

Rich Maniscalco

Philliam said:
You should be able to make a DLL and have it export the correct
symbols for your functions, and put the DLL file in C:/WINDOWS/
system32 (may be just C:/WINDOWS/ or C:/WINDOWS/system/, can't
remember) and you can use your own DLL the same way. I'm not sure how
to do it any other way without making your own ruby extension, which I
found impossible.


That didn't work. I am going to rebuild Ruby and my DLL's using VC++
version 9. Hopefully that will resolve the issues. I'll report the
outcome.

Thanks,

Rich
 
E

Eleanor McHugh

That didn't work. I am going to rebuild Ruby and my DLL's using VC++=20=
version 9. Hopefully that will resolve the issues. I'll report the=20=


I've not used Windows for development in about seven years so take the =
following with a pinch of salt.

Ruby/DL allows dynamic loading of Windows DLLs and ships as part of =
Ruby's standard library. You'll find links to what exists in the way of =
English documentation in the Ruby Plumber's Guide to Unix presentation =
linked to in my signature, but unfortunately there's very little =
documentation online regarding its use under Windows.

At the least you'll have to figure out the function signatures for the =
DLL routines you want to access by trial and error and there'll probably =
also be issues with type conversion...

An alternative would be to rewrite your DLLs as Windows COM servers so =
you could use the WinOLE library to access them.


Ellie

Eleanor McHugh
Games With Brains
http://slides.games-with-brains.net
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,608
Members
45,250
Latest member
Charlesreero

Latest Threads

Top