Utilizing dlls in windows programming?

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). 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), 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

any help, hints or tips would be much appreciated.

thanks

Hi,

From: "warhero" <beingthexemplarylists@gmail.com>
Reply-To: ruby-talk@ruby-lang.org
To: ruby-talk@ruby-lang.org (ruby-talk ML)
Subject: utilizing dlls in windows programming?
Date: Mon, 4 Dec 2006 14:55:07 +0900

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.

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

My second question:

I am trying to utilize a DLL that is for phidgets (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\), 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

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 Heesob

···

_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today it's FREE! http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/

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

···

On Dec 4, 5:00 am, "Park Heesob" <phasi...@hotmail.com> wrote:

Hi,

>From: "warhero" <beingthexemplaryli...@gmail.com>
>Reply-To: ruby-t...@ruby-lang.org
>To: ruby-t...@ruby-lang.org (ruby-talk ML)
>Subject: utilizing dlls in windows programming?
>Date: Mon, 4 Dec 2006 14:55:07 +0900

>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.Refer tohttp://weblog.jamisbuck.org/2004/12/30/disappointments-in-ruby-land
andhttp://rubyforge.org/pipermail/win32utils-devel/2005-February/000294....

>My second question:

>I am trying to utilize a DLL that is for phidgets (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\), 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

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

_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today it's FREE!http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/