Ruby has powerful functions. The Ruby module Win32API we will introduce here is an additional library in the Ruby language. It can help us call Win32API directly.
- Example of Ruby code for getting the current class name
- Ruby module OpenURI to get http/FTP address content
- Analysis of Ruby encryption implementation code examples
- Ruby blocks provides flexible encoding methods
- Parse Json IN Ruby
Parameter 1 string Call dll name
Parameter 2 Name of the dllexport in the string dll
Parameter 3 String Array represents the type of each parameter L represents Long P represents Point I represents Int V represents Void (in actual use, HResult and various Handle are both Long and the string is P)
Parameter 4 string indicates the same type as the return value.
Ruby module Win32API sample code:
- Require "dl/win32"
- FindWindow = Win32API. new
'User32. dll ', 'findwindow', % w (l p), 'l'
- SetWindowText = Win32API. new
'User32. dll ', 'setwindowtext ',
% W (l p), 'I'
- If ARGV. length = 0 then
- Puts "usage instructions :"
- Puts "a parameter is used to view the Form ID based on the Form title"
- When puts are two parameters, they are queried Based on the title of parameter 1.
Find the form and change it to the title of parameter 2"
- Elsif ARGV. length>0 then
- Win = FindWindow. call (0, ARGV. shift)
- Puts win
- If win! = 0 then
- BSet = SetWindowText. call (win,
ARGV. shift)
- If bSet = 1 then
- Puts "Success! "
- Else
- Puts "Fail! "
- End
- End
- End
The preceding section describes how to use Win32API in Ruby.