Ruby module Win32API calls win32API directly

Source: Internet
Author: User

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:

  1. Require "dl/win32"
  2. FindWindow = Win32API. new
    'User32. dll ', 'findwindow', % w (l p), 'l'
  3. SetWindowText = Win32API. new
    'User32. dll ', 'setwindowtext ',
    % W (l p), 'I'
  4. If ARGV. length = 0 then
  5. Puts "usage instructions :"
  6. Puts "a parameter is used to view the Form ID based on the Form title"
  7. 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"
  8. Elsif ARGV. length>0 then
  9. Win = FindWindow. call (0, ARGV. shift)
  10. Puts win
  11. If win! = 0 then
  12. BSet = SetWindowText. call (win,
    ARGV. shift)
  13. If bSet = 1 then
  14. Puts "Success! "
  15. Else
  16. Puts "Fail! "
  17. End
  18. End
  19. End

The preceding section describes how to use Win32API in Ruby.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.