preload
Mar 16

If you try to “compile” a Ruby script that has the Watir gem in it with OCRA, you will find that running the compiled .exe file on a computer without the Watir gem previously being installed may result in this error:

c:/ruby/lib/ruby/gems/1.8/gems/watir-1.6.2/lib/watir/ie.rb:113:in `initialize': unknown OLE server: `AutoItX3.Control' (WIN32OLERuntimeError)
    HRESULT error code:0x800401f3
      Invalid class string      from c:/ruby/lib/ruby/gems/1.8/gems/watir-1.6.2/lib/watir/ie.rb:113:in `new'
        from c:/ruby/lib/ruby/gems/1.8/gems/watir-1.6.2/lib/watir/ie.rb:113:in `autoit'
        from c:/ruby/lib/ruby/gems/1.8/gems/watir-1.6.2/lib/watir/ie-class.rb:425:in `autoit'
        from c:/ruby/lib/ruby/gems/1.8/gems/watir-1.6.2/lib/watir/ie-class.rb:422:in `set_window_state'
        from c:/ruby/lib/ruby/gems/1.8/gems/watir-1.6.2/lib/watir/ie-class.rb:398:in `maximize'
        ...

Huh? Why am I getting a WIN32OLE error? This all runs fine on my computer when I tested it! … Well, it seems that Watir uses its own version of a win32ole gem, and not the one that you already have installed. In fact, when you compile a Ruby script that has both win32ole and watir gems, you will need to comment out the “require ‘win32ole’” line in order for it to work. Anyway… as part of the win32ole gem install, it seems that it registers the AutoItX3.dll file into the registry. OCRA will, however, *NOT* copy this file over and register it for you, so you may see the error above.

So…the trick is add the AutoItX3.dll file to your OCRA compile, and to temporarily register the DLL before calling watir or win32ole commands. I simply copied the DLL from the win32ole gem directory to my Ruby script’s working directory, and then added it to my OCRA compile command:

C:\Server4\Dev\MyProg>ocra --console --icon c:/Server4/Dev/icons/exonets.ico myprog.rb AutoItX3.dll

OCRA will add the DLL to the EXE and when run will place it in the current temporary directory. After that you need to run the DLL register command to make it an OLE server, then when done, be sure to unregister it before your program completes.
Here a sample of code that I use to accomplish all this: Continue reading »

SociBook del.icio.us Digg Facebook Google Yahoo Buzz StumbleUpon
Tagged with:
Feb 11

When I want to distribute a Ruby script to a customer, sometimes its just easier to use something like Ocra to package up all the files needed into one nice .exe file that I can send over. Since I use Rake a lot, I wanted to figure out a way to automate the process. Here’s a simple example:

...
desc "List available Tasks"
task :default do
   sh %{ rake -T }
end

desc "Make BI_Competition_Status_Report.exe file"
task :exe do
   sh %{ cd lib && rake exe }
   sh %{ move lib\\BI_Competition_Status_Report.exe .}
end
...

This is in your main project Rakefile. Since I’m using NetBeans, it places my Ruby files in a ./lib directory. The first sh command simply CD’s down to lib, and runs a second Rakefile located there:

desc "Make BI_Competition_Status_Report.exe file"
task :exe do
   sh %{ ocra --windows --icon C:/Server12/Dev/Ruby/Exonets.ico BI_Competition_Status_Report.rb}
end

This is the actual Ocra command that packages up the Ruby app into a single .exe file. When this rake command ends, the last command in the previous Rakefile moves the completed .exe file up to the current directory.

SociBook del.icio.us Digg Facebook Google Yahoo Buzz StumbleUpon
Tagged with: