# Utilizing dlls in windows programming?

**URL:** <https://www.ruby-forum.com/t/utilizing-dlls-in-windows-programming/78229>\
**Category:** Ruby\
**Created:** [December 4, 2006, 6:56am UTC](https://www.ruby-forum.com/t/utilizing-dlls-in-windows-programming/78229 "2006-12-04T06:56:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![warhero](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/8baadc/32.png) [@warhero](https://www.ruby-forum.com/u/warhero)\
**Post date:** [December 4, 2006, 6:56am UTC](https://www.ruby-forum.com/t/utilizing-dlls-in-windows-programming/78229/1 "2006-12-04T06:56:27Z")

</div>

This is a two part question:

I have been reading the pick-axe book and was reading the chapter on  
ruby and windows. I was reading documentation on the DL library. (is  
library the correct term for that?), but my question: what is the  
difference in the Win32API and using say DL.dlopen? Also in reading the  
documentation on the Win32API in the back of the book, it said that  
Win32API is more than likely going to be phased out.

My second question:

I am trying to utilize a DLL that is for phidgets ([phidgets.com](http://phidgets.com)). They  
have a dll (phidget21.dll) that is supposed to be used to gain access  
to controlling their hardware. I’ve looked at their documentation for  
the C language. Is that usually what a dll is written in? C? You can  
download what I am looking at from the documentation section. (The C  
API Manual ). I’ve tried a couple of different ways to try and use the  
dll. Nothing as succeeded. I’ve tried the Win32API and the DL.dlopen.  
It’s probably just the way i’m trying to use it. here is what im  
trying:

require “dl”  
Phidget21 = DL.dlopen(“phidget21”);  
f = Phidget21[“CPhidgetRFID\_create”, “S”]  
handle = f.call()  
open = Phidget21[“CPhidget\_open”, “II”]  
open.call( 25807 )

The first problem is that handle = nil. Besides that, I don’t  
understand fully how to be passing back and forth parameters to the  
dlls. This example cause the interactive ruby to crash (terminates in  
an unusual way). I know this isn’t all that’s needed to work with the  
phidgets, but i’m just trying to go step by step and even get it setup  
correctly.

download the phidget21.dll  
([http://www.smithaaronlee.net/downloads/phidget21.dll](http://www.smithaaronlee.net/downloads/phidget21.dll)), i’ve posted the  
dll online. Also, here is a direct link to the C API  
:[http://www.phidgets.com/documentation/C\_API\_Manual\_Phidget21.pdf](http://www.phidgets.com/documentation/C_API_Manual_Phidget21.pdf)

any help, hints or tips would be much appreciated.

thanks

---

<div class="post-metadata">

**Author:** ![warhero](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/8baadc/32.png) [@warhero](https://www.ruby-forum.com/u/warhero)\
**Post date:** [December 4, 2006, 11:02am UTC](https://www.ruby-forum.com/t/utilizing-dlls-in-windows-programming/78229/2 "2006-12-04T11:02:50Z")

</div>

Hi,

> library the correct term for that?), but my question: what is the  
> difference in the Win32API and using say DL.dlopen? Also in reading the  
> documentation on the Win32API in the back of the book, it said that  
> Win32API is more than likely going to be phased out.

Refer to  
[http://weblog.jamisbuck.org/2004/12/30/disappointments-in-ruby-land](http://weblog.jamisbuck.org/2004/12/30/disappointments-in-ruby-land)  
and  
[http://rubyforge.org/pipermail/win32utils-devel/2005-February/000294.html](http://rubyforge.org/pipermail/win32utils-devel/2005-February/000294.html)

> It’s probably just the way i’m trying to use it. here is what im  
> understand fully how to be passing back and forth parameters to the  
> any help, hints or tips would be much appreciated.

The following code will work for you:

require ‘dl’  
Phidget21 = DL.dlopen(‘phidget21’)  
CPhidgetRFID\_create = Phidget21[‘CPhidgetRFID\_create’, ‘LP’]  
handleptr = [0].pack(‘L’).to\_ptr  
CPhidgetRFID\_create.call(handleptr)  
handle = handleptr.to\_i  
CPhidget\_open = Phidget21[‘CPhidget\_open’, ‘ILI’]  
CPhidget\_open.call( handle,-1 )

Or

require ‘Win32API’  
CPhidgetRFID\_create =  
Win32API.new(‘phidget21.dll’,‘CPhidgetRFID\_create’,‘P’,‘I’)  
CPhidget\_open = Win32API.new(‘phidget21.dll’,‘CPhidget\_open’,‘LI’,‘I’)  
handleptr = [0].pack(‘L’)  
CPhidgetRFID\_create.call(handleptr)  
handle = handleptr.unpack(‘L’)[0]  
CPhidget\_open.call(handle,-1)

Regards,

Park H.

---

<div class="post-metadata">

**Author:** ![warhero](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/8baadc/32.png) [@warhero](https://www.ruby-forum.com/u/warhero)\
**Post date:** [December 4, 2006, 9:00pm UTC](https://www.ruby-forum.com/t/utilizing-dlls-in-windows-programming/78229/3 "2006-12-04T21:00:56Z")

</div>

Thanks, do you have previous experience with Phidgets and ruby?
