The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> Ruby Programming
|
LoadLibrary & GetProcAddress Problem
Discuss LoadLibrary & GetProcAddress Problem in the Ruby Programming forum on Dev Shed. LoadLibrary & GetProcAddress Problem Ruby and Ruby on Rails programming forum covering Ruby Tips and Tricks, Best Practices, and agile development with Ruby on Rails.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

September 17th, 2012, 11:51 PM
|
|
Registered User
|
|
Join Date: Sep 2012
Posts: 3
Time spent in forums: 57 m 23 sec
Reputation 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?
|

September 18th, 2012, 02:55 AM
|
 |
pollyanna
|
|
Join Date: Jul 2012
Location: Germany
|
|
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".
|

September 18th, 2012, 03:16 AM
|
|
Registered User
|
|
Join Date: Sep 2012
Posts: 3
Time spent in forums: 57 m 23 sec
Reputation Power: 0
|
|
Quote: | 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:
Quote: 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 03:32 AM.
Reason: Forgot to change all the variables.
|

September 18th, 2012, 04:13 AM
|
 |
pollyanna
|
|
Join Date: Jul 2012
Location: Germany
|
|
|
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.
|

September 18th, 2012, 04:59 AM
|
|
Registered User
|
|
Join Date: Sep 2012
Posts: 3
Time spent in forums: 57 m 23 sec
Reputation Power: 0
|
|
Quote: | 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  .
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|