Ruby 1.9.0 problem with DL.dlopen

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.

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.

and , how to call GetPixel :

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

how to call GetPixel , use dlopen ?

$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

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.