# Ruby 1.9.0 problem with DL.dlopen

**URL:** <https://www.ruby-forum.com/t/ruby-1-9-0-problem-with-dl-dlopen/125580>\
**Category:** Ruby\
**Created:** [January 10, 2008, 10:32am UTC](https://www.ruby-forum.com/t/ruby-1-9-0-problem-with-dl-dlopen/125580 "2008-01-10T10:32:47Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![chauk-mean](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/d07c76/32.png) [@chauk-mean](https://www.ruby-forum.com/u/chauk-mean)\
**Post date:** [January 10, 2008, 10:32am UTC](https://www.ruby-forum.com/t/ruby-1-9-0-problem-with-dl-dlopen/125580/1 "2008-01-10T10:32:47Z")

</div>

Hi,

The following code runs with ruby 1.8.6 (2007-09-24 patchlevel 111)  
[i386-mswin32] on Windows :

require ‘dl’  
user32 = DL.dlopen(‘user32’)  
msgbox = user32[‘MessageBoxA’, ‘ILSSI’]  
msgbox.call(0, “Hello”, “Message Box”, 0)

A message box is displayed with just the OK button.

If I run the same code with ruby 1.9.0 (2007-12-25 revision 14709)  
[i386-mswin32], the following error is output :

win\_msgbox.rb:3:in `[]': wrong number of arguments(2 for 1) (ArgumentError) from win_msgbox.rb:3:in`’

If I just remove the ‘ILSSI’ argument, this does not work either.

Thanks for any help.

Chauk-Mean.

---

<div class="post-metadata">

**Author:** ![chauk-mean](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/d07c76/32.png) [@chauk-mean](https://www.ruby-forum.com/u/chauk-mean)\
**Post date:** [January 18, 2008, 4:11pm UTC](https://www.ruby-forum.com/t/ruby-1-9-0-problem-with-dl-dlopen/125580/2 "2008-01-18T16:11:12Z")

</div>

In case it would be useful for someone else, I received the following  
answer from the development team :

* * *

Date: 18/01/2008 07:47  
ExpÃ©diteur: Usaku Nakamura

Not a bug.  
Date: 18/01/2008 07:47  
ExpÃ©diteur: Usaku Nakamura

1.9’s dl is not compatible with 1.8’s.  
The following code may help you:

## require ‘dl’ user32 = DL.dlopen(‘user32’) msgbox = DL::CFunc.new(user32[‘MessageBoxA’], DL::TYPE\_LONG, ‘MessageBox’) msgbox.call([0, “Hello”, “Message Box”, 0].pack(‘L!ppL!’).unpack(‘L!\*’))

Chauk-Mean.

---

<div class="post-metadata">

**Author:** ![chauk-mean](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/d07c76/32.png) [@chauk-mean](https://www.ruby-forum.com/u/chauk-mean)\
**Post date:** [September 23, 2013, 3:15pm UTC](https://www.ruby-forum.com/t/ruby-1-9-0-problem-with-dl-dlopen/125580/3 "2013-09-23T15:15:35Z")

</div>

and , how to call GetPixel :

> **[GetPixel function (wingdi.h) - Win32 apps](https://learn.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-getpixel?redirectedfrom=MSDN)**
>
> The GetPixel function retrieves the red, green, blue (RGB) color value of the pixel at the specified coordinates.

COLORREF GetPixel(  
_In_ HDC hdc,  
_In_ int nXPos,  
_In_ int nYPos  
);

how to call GetPixel , use dlopen ?

---

<div class="post-metadata">

**Author:** ![chauk-mean](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/d07c76/32.png) [@chauk-mean](https://www.ruby-forum.com/u/chauk-mean)\
**Post date:** [September 23, 2013, 3:22pm UTC](https://www.ruby-forum.com/t/ruby-1-9-0-problem-with-dl-dlopen/125580/4 "2013-09-23T15:22:24Z")

</div>

$a = DL.dlopen(‘gdi32’)

def GetPixel hwnd,x,y  
getp = $a[‘GetPixel’]  
getp.call(hwnd,x,y)  
end

def SetPixel hwnd,x,y  
setp = $a[‘SetPixel’]  
setp.call(hwnd,x,y)  
end

p GetPixel 0,1,1

exit

err: NoMethodError: undefined method `call’ for 1997915093:Fixnum

---

<div class="post-metadata">

**Author:** ![chauk-mean](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/d07c76/32.png) [@chauk-mean](https://www.ruby-forum.com/u/chauk-mean)\
**Post date:** [September 23, 2013, 4:29pm UTC](https://www.ruby-forum.com/t/ruby-1-9-0-problem-with-dl-dlopen/125580/5 "2013-09-23T16:29:06Z")

</div>

Kk Kk wrote in post #1122159:

> $a = DL.dlopen(‘gdi32’)
> 
> def GetPixel hwnd,x,y  
> getp = $a[‘GetPixel’]  
> getp.call(hwnd,x,y)  
> end
> 
> def SetPixel hwnd,x,y  
> setp = $a[‘SetPixel’]  
> setp.call(hwnd,x,y)  
> end
> 
> p GetPixel 0,1,1
> 
> exit
> 
> err: NoMethodError: undefined method `call’ for 1997915093:Fixnum

You can call GetPixel like this:

require ‘dl/func’  
$gdi32 = DL.dlopen(‘gdi32’)

def GetPixel hwnd,x,y  
getpixel = DL::Function.new(DL::CFunc.new($gdi32[‘GetPixel’],  
DL::TYPE\_LONG,‘GetPixcel’),[DL::TYPE\_LONG,DL::TYPE\_INT,DL::TYPE\_INT])  
getpixel.call(hwnd,x,y)  
end

p GetPixel 0,1,1

Regards,  
Park H.
