Calling the Unicode Version of a DLL Function

Suppose that instead of calling the ANSI version of the MessageBox function, you want to call the Unicode version. You can do this by using the unicode modifier with the @dll.import directive:

/** @dll.import("USER32",unicode) */
  static native int MessageBox(int hwnd, String text, String title,
                               int style);

Since the unicode modifier is present, the Microsoft VM will go through the following steps:

  1. The strings "text" and "title" are converted to Unicode null-terminated strings.

  2. The VM attempts to find an export named MessageBox in USER32.DLL.

  3. This attempt fails. The VM appends a "W" onto the name and looks for an export named MessageBoxW.

  4. This attempt succeeds, and the VM invokes the MessageBoxW function.