Ruby charm: directly calling WIN32API

Source: Internet
Author: User
Ruby is very powerful. You can use the WIN32API module of the additional database DL/Win32 to directly call WIN32API

WIN32API. New
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.

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 " Instructions for use: "
Puts " A parameter is used to view the Form ID based on the Form title. "
Puts " When there are two parameters, the form is searched based on the title of parameter 1, and then changed 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
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.