#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Posts
    3
    Rep Power
    0

    LoadLibrary & GetProcAddress Problem


    Hello one and all,

    I'm new to Ruby and i have been trying to get this piece of code to call
    MessageBox but can't. I know I am missing something but I don't know
    what it is. Any help with this would be greatly appreciated!

    Here is the code so far:

    Code:
    require 'Win32API'
    
    LoadLibrary = Win32API.new('kernel32','LoadLibrary','P','L')
    GetProcAddress = Win32API.new('kernel32','GetProcAddress','LP','L')
    
    Load = LoadLibrary.call('user32.dll')
    Proc = GetProcAddress.call(Load,'MessageBox')
    
    Proc.call(0,"Hello World!","MessageBox in Ruby",0)
    I know everything is ok except my "Proc.call". What am I missing?
  2. #2
  3. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,959
    Rep Power
    1014
    Cross posted at stackoverflow

    We need a concrete error description. Saying that the code "doesn't work" doesn't tell us anything.

    In any case, you cannot use uppercase identifiers as variable names. Those are interpreted as constants, immediately leading to a naming conflict with the internal Ruby class "Proc".
    The 6 worst sins of security ē How to (properly) access a MySQL database with PHP

    Why canít I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Posts
    3
    Rep Power
    0
    Originally Posted by Jacques1
    Cross posted at stackoverflow

    We need a concrete error description. Saying that the code "doesn't work" doesn't tell us anything.

    In any case, you cannot use uppercase identifiers as variable names. Those are interpreted as constants, immediately leading to a naming conflict with the internal Ruby class "Proc".
    Thank you for the help so far Jacques1. Yeah I have been posting this question to a few forums in hopes I can get some help since there are not many active Ruby sections around. Thank you for taking the time to help me.

    I changed all the variable names to lowercase:

    Code:
    require 'Win32API'
    
    loadlibrary = Win32API.new('kernel32','LoadLibrary','P','L')
    getprocaddress = Win32API.new('kernel32','GetProcAddress','LP','L')
    
    load = loadlibrary.call('user32.dll')
    process = getprocaddress.call(load,'MessageBox')
    
    process.call(0,"Hello World!","MessageBox in Ruby",0)
    And here is my error output:

    test.rb:9:in '<main>': undefined method
    'call' for 0:Fixnum (NoMethodError)
    I don't know what any of that means.
    Last edited by Huxley; September 18th, 2012 at 04:32 AM. Reason: Forgot to change all the variables.
  6. #4
  7. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,959
    Rep Power
    1014
    The message is saying that in line 9 you're trying to call a method named "call" on an integer (which of course doesn't work). In other words: The process variable set by getprocaddress.call is an integer, although you obviously expect some other object -- or you have some logical error in your program.

    Anyway, is there a reason why you need to dig into these lowlevel Windows functions? If you just want to display a window, there are much better ways. You should use one of the GUI libraries available in Ruby (like Gtk, Qt, RubyFX, Shoes etc.). They're much easier to use and not bound to a specific platform.
    The 6 worst sins of security ē How to (properly) access a MySQL database with PHP

    Why canít I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Posts
    3
    Rep Power
    0
    Originally Posted by Jacques1
    The message is saying that in line 9 you're trying to call a method named "call" on an integer (which of course doesn't work). In other words: The process variable set by getprocaddress.call is an integer, although you obviously expect some other object -- or you have some logical error in your program.

    Anyway, is there a reason why you need to dig into these lowlevel Windows functions? If you just want to display a window, there are much better ways. You should use one of the GUI libraries available in Ruby (like Gtk, Qt, RubyFX, Shoes etc.). They're much easier to use and not bound to a specific platform.
    Oh ok. Thank you for explaining that. That was the only code in my program so I guess there is something it doesn't like lol.

    No reason at all. I was just trying to see if I could accomplish this task. I like playing with Windows API's and wanted to see If I could get this to work.

    I thank you again for all of the help. I will take your advise and use the GUI libraries instead of going so low level .

IMN logo majestic logo threadwatch logo seochat tools logo