All atomic-powered posts from June 2008:
Finder Objects in Rails
ActiveRecord is perhaps the most compelling component of Ruby on Rails. ActiveRecord makes it easy to create a record, or to find one, or even to migrate the database schema. Unfortunately those “find” methods can be a little too seductive. Let’s see why.
Read the rest of this entryGoogle I/O Impressions
Atomic Object provides some fantastic benefits. For example, Atomic sends each developer to one conference each year. They pay the registration, air fare, and hotel. They also pay as if I had been actually working. It’s fantastic to have an employer that not only wants me to be a better developer, but takes the extra steps to help me improve.
This year, I attended the Google I/O conference in San Francisco. The first day’s keynote was essentially a bird’s eye view of the conference content. The overall theme was that Google wants to advance capabilities of web applications. They understand that their growth is tied to the growth of internet use at large. They understand that internet use will increase as web applications improve. They want to facilitate the improvement of web applications by providing tools for developers to use. As much as possible, these tools are open source, and not bound to Google, as that is the best way to empower the advancement of the internet.
Read the rest of this entryRuby and Unicode Win32 MessageBoxes
Have you ever needed to display Unicode characters in a Win32 MessageBox from a Ruby script? My pair and I needed to do just that and so I thought I would share what we found.
There are a number of ways to access Win32 calls from a Ruby script. The code we were working with did the following:
1 2 3 4 5 6 7 8 9 |
require 'dl' def show_message_box(message, title) mb_ok = 0 mb_iconexclamation = 48 user32 = DL.dlopen("user32") message_box = user32['MessageBoxA', 'ILSSI'] message_box.call(0, message, title, mb_ok | mb_iconexclamation) end |
That works well until you need to display Unicode characters in the MessageBox. It turns out the MessageBoxA version of the function is for ASCII characters. There is another version of the API call, MessageBoxW, that can handle Unicode, or wide characters. So the issue becomes converting your Ruby string into a wide string so it can be passed to MessageBoxW. The MultiByteToWideChar Win32 call can do this for you. And the windows-pr gem (from win32utils) adds a nice ruby wrapper around the function.
gem install windows-pr |
1 2 3 4 5 |
require 'windows/unicode' include Windows::Unicode $KCODE='UTF8' str = multi_to_wide("This is a test") |
This seemed to work quite well for the most part. However, from time to time we would see garbage text showing up at the end of our messages. It could easily be reproduced if the message was very short.

Having done enough C/C++ coding to recognize a string that was not being null terminated, we experimented with adding null characters to the end of the string. It turns out a wide null terminator (”\0\0”) is needed. The following code will properly display Unicode characters in a Win32 MessageBox:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
require 'dl' require 'windows/unicode' include Windows::Unicode $KCODE='UTF8' def win32_wide(text) multi_to_wide(text) + "\0\0" end def show_message_box(message, title) mb_ok = 0 mb_iconexclamation = 48 user32 = DL.dlopen("user32") message_box = user32['MessageBoxW', 'ILSSI'] message_box.call(0, win32_wide(message), win32_wide(title), mb_ok | mb_iconexclamation) end show_message_box "MessageBox displayed from Ρουμπίνι", "¡Alert!" |