Ruby Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesRuby Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old September 17th, 2012, 11:51 PM
Huxley Huxley is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2012
Posts: 3 Huxley User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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?

Reply With Quote
  #2  
Old September 18th, 2012, 02:55 AM
Jacques1's Avatar
Jacques1 Jacques1 is offline
pollyanna
Click here for more information.
 
Join Date: Jul 2012
Location: Germany
Posts: 1,835 Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 1 Day 4 h 14 m 14 sec
Reputation Power: 811
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".

Reply With Quote
  #3  
Old September 18th, 2012, 03:16 AM
Huxley Huxley is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2012
Posts: 3 Huxley User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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.

Reply With Quote
  #4  
Old September 18th, 2012, 04:13 AM
Jacques1's Avatar
Jacques1 Jacques1 is offline
pollyanna
Click here for more information.
 
Join Date: Jul 2012
Location: Germany
Posts: 1,835 Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 1 Day 4 h 14 m 14 sec
Reputation Power: 811
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.

Reply With Quote
  #5  
Old September 18th, 2012, 04:59 AM
Huxley Huxley is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2012
Posts: 3 Huxley User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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 .

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesRuby Programming > LoadLibrary & GetProcAddress Problem

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap