Forum: Ruby Ruby 1.9.0 problem with DL.dlopen

00109e19a784b64f81b483a5dbec690a?d=identicon&s=25 Chauk-Mean Proum (chauk-mean)
on 2008-01-10 10:32
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 `<main>'

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

Thanks for any help.

Chauk-Mean.
00109e19a784b64f81b483a5dbec690a?d=identicon&s=25 Chauk-Mean Proum (chauk-mean)
on 2008-01-18 16:11
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.
5e7b759194d86939d23a716ad88d92dc?d=identicon&s=25 Kk Kk (sevk)
on 2013-09-23 15:15
and , how to call GetPixel :


http://msdn.microsoft.com/en-us/library/windows/de...

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

how to call GetPixel , use dlopen ?
5e7b759194d86939d23a716ad88d92dc?d=identicon&s=25 Kk Kk (sevk)
on 2013-09-23 15:22
$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
666b4e17b4bb0e2d999037a25f65a7cb?d=identicon&s=25 Heesob Park (phasis)
on 2013-09-23 16:29
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 Heesob
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.