Ruby win32api , GetPixel 如何调用?

sevk · September 23, 2013 · Last by sevk replied at September 23, 2013 · 3366 hits

Gdi32.dll

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

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


Public Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long

这个 api ,如何用 Ruby::Fiddle 调用? 或有其他好办法吗?

一般 ruby2.0 里面是建议 Ruby::Fiddle 的吧 ?

$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

建议用 ffi 调用外部库函数

#2 楼 @windwiny 哦,我去试试多谢

You need to Sign in before reply, if you don't have an account, please Sign up first.