# Newbie question: Accessiong non-Windows DLL's

**URL:** <https://rubytalk.org/t/newbie-question-accessiong-non-windows-dlls/57196>\
**Category:** ruby-talk\
**Created:** [29 January 2010 20:50 UTC](https://rubytalk.org/t/newbie-question-accessiong-non-windows-dlls/57196 "2010-01-29T20:50:49Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rich\_Maniscalco](https://avatars.discourse-cdn.com/v4/letter/r/a8b319/32.png) [@Rich\_Maniscalco](https://rubytalk.org/u/Rich_Maniscalco)\
**Post date:** [29 January 2010 20:50 UTC](https://rubytalk.org/t/newbie-question-accessiong-non-windows-dlls/57196/1 "2010-01-29T20:50:49Z")

</div>

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,

&nbsp;&nbsp;Rich

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

---

<div class="post-metadata">

**Author:** ![Philliam\_Auriemma](https://avatars.discourse-cdn.com/v4/letter/p/edb3f5/32.png) [@Philliam\_Auriemma](https://rubytalk.org/u/Philliam_Auriemma)\
**Post date:** [29 January 2010 21:00 UTC](https://rubytalk.org/t/newbie-question-accessiong-non-windows-dlls/57196/2 "2010-01-29T21:00:05Z")

</div>

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/](http://www.rubytips.org/2008/05/13/accessing-windows-api-from-ruby-using-win32api-library/)

> **···**
>
> On Jan 29, 12:50 pm, Rich Maniscalco \<tmpr...@gmail.com\> wrote:
> 
> > 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  
> > --  
> > Posted viahttp://www.ruby-forum.com/.

---

<div class="post-metadata">

**Author:** ![Roger\_Pack4](https://avatars.discourse-cdn.com/v4/letter/r/bb73d2/32.png) [@Roger\_Pack4](https://rubytalk.org/u/Roger_Pack4)\
**Post date:** [29 January 2010 21:24 UTC](https://rubytalk.org/t/newbie-question-accessiong-non-windows-dlls/57196/3 "2010-01-29T21:24:24Z")

</div>

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

FFI might work.  
-r

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![Roger\_Pack4](https://avatars.discourse-cdn.com/v4/letter/r/bb73d2/32.png) [@Roger\_Pack4](https://rubytalk.org/u/Roger_Pack4)\
**Post date:** [29 January 2010 21:29 UTC](https://rubytalk.org/t/newbie-question-accessiong-non-windows-dlls/57196/4 "2010-01-29T21:29:08Z")

</div>

> 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

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![Rich\_Maniscalco](https://avatars.discourse-cdn.com/v4/letter/r/a8b319/32.png) [@Rich\_Maniscalco](https://rubytalk.org/u/Rich_Maniscalco)\
**Post date:** [29 January 2010 21:26 UTC](https://rubytalk.org/t/newbie-question-accessiong-non-windows-dlls/57196/5 "2010-01-29T21:26:11Z")

</div>

Philliam Auriemma wrote:

> **···**
>
> > On Jan 29, 12:50?pm, Rich Maniscalco \<tmpr...@gmail.com\> wrote:
> > 
> > > prints "Hello World" and had the same Ruby error.  
> > > Posted viahttp://www.ruby-forum.com/.
> > 
> > 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/](http://www.rubytips.org/2008/05/13/accessing-windows-api-from-ruby-using-win32api-library/)
> 
> 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,
> 
> &nbsp;&nbsp;Rich  
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![Rich\_Maniscalco](https://avatars.discourse-cdn.com/v4/letter/r/a8b319/32.png) [@Rich\_Maniscalco](https://rubytalk.org/u/Rich_Maniscalco)\
**Post date:** [29 January 2010 21:37 UTC](https://rubytalk.org/t/newbie-question-accessiong-non-windows-dlls/57196/6 "2010-01-29T21:37:22Z")

</div>

Roger Pack wrote:

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

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,

&nbsp;&nbsp;Rich

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![Philliam\_Auriemma](https://avatars.discourse-cdn.com/v4/letter/p/edb3f5/32.png) [@Philliam\_Auriemma](https://rubytalk.org/u/Philliam_Auriemma)\
**Post date:** [29 January 2010 21:40 UTC](https://rubytalk.org/t/newbie-question-accessiong-non-windows-dlls/57196/7 "2010-01-29T21:40:21Z")

</div>

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.

> **···**
>
> On Jan 29, 1:26 pm, Rich Maniscalco \<tmpr...@gmail.com\> wrote:
> 
> > Philliam Auriemma wrote:  
> > \> On Jan 29, 12:50?pm, Rich Maniscalco \<tmpr...@gmail.com\> wrote:  
> > \>\> prints "Hello World" and had the same Ruby error.  
> > \>\> Posted viahttp://www.ruby-forum.com/.  
> > \> 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-us\.\.\](http://www.rubytips.org/2008/05/13/accessing-windows-api-from-ruby-us%5C.%5C.%5C).
> > 
> > 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  
> > --  
> > Posted viahttp://www.ruby-forum.com/.

---

<div class="post-metadata">

**Author:** ![Rich\_Maniscalco](https://avatars.discourse-cdn.com/v4/letter/r/a8b319/32.png) [@Rich\_Maniscalco](https://rubytalk.org/u/Rich_Maniscalco)\
**Post date:** [29 January 2010 21:41 UTC](https://rubytalk.org/t/newbie-question-accessiong-non-windows-dlls/57196/8 "2010-01-29T21:41:07Z")

</div>

Rich Maniscalco wrote:

> Roger Pack wrote:
> 
> > > 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
> 
> 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,
> 
> &nbsp;&nbsp;Rich

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

&nbsp;&nbsp;Rich

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![Rich\_Maniscalco](https://avatars.discourse-cdn.com/v4/letter/r/a8b319/32.png) [@Rich\_Maniscalco](https://rubytalk.org/u/Rich_Maniscalco)\
**Post date:** [29 January 2010 22:24 UTC](https://rubytalk.org/t/newbie-question-accessiong-non-windows-dlls/57196/9 "2010-01-29T22:24:29Z")

</div>

Philliam Auriemma wrote:

> **···**
>
> > On Jan 29, 1:26?pm, Rich Maniscalco \<tmpr...@gmail.com\> wrote:
> > 
> > > 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  
> > > --  
> > > Posted viahttp://www.ruby-forum.com/.
> > 
> > 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,
> 
> &nbsp;&nbsp;Rich  
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![Eleanor\_McHugh](https://avatars.discourse-cdn.com/v4/letter/e/8c91f0/32.png) [@Eleanor\_McHugh](https://rubytalk.org/u/Eleanor_McHugh)\
**Post date:** [31 January 2010 14:22 UTC](https://rubytalk.org/t/newbie-question-accessiong-non-windows-dlls/57196/10 "2010-01-31T14:22:17Z")

</div>

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](http://slides.games-with-brains.net)

> **···**
>
> On 29 Jan 2010, at 22:24, Rich Maniscalco wrote:
> 
> > 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.
> 
> ----  
> raise ArgumentError unless @reality.responds\_to? :reason
