Page 1 of 1

API

Posted: Fri Apr 01, 2016 5:18 pm
by S1User
If anyone knows...

Why does triggering this Ruby code with a button work in design mode but when I compile it to a standalone exe it doesn't work?

Code: Select all

require 'win32API'

api = Win32API.new('user32', 'MessageBox', ['L', 'P', 'P', 'L'], 'I')

message = "This is a sample Windows message box generated using Win32API"
title = "Win32API from Ruby"

api.call(0,message,title,0)

Re: API

Posted: Fri Apr 01, 2016 10:25 pm
by Tronic
You have to include the right ruby library folder in
$LOAD_PATH global variable
ruby use it to search the required file

Code: Select all

# set the current exe ruby library directory to work with
Dir.chdir("C:\\your app folder\\ruby_library")
# list all sub directory
your_lib_dir=Dir["**/"].reject{|o| not File.directory?(o)}
your_lib_dir.each {|dir|
   path = File.expand_path(dir)
   # add the path to $LOAD_PATH where ruby search for the require method
   $LOAD_PATH.unshift path unless $LOAD_PATH.include? path
   }


When you ship or install your application in other pc, you have to enclose the required file with it.
./-- exe folder
     |
     |--ruby_library