Microsoft Layer For Unicode - How IT Works

How It Works

Normally, the Windows API provides both A (ANSI) and W (Wide-character) versions of most functions. On Windows 95/98/ME, only the A versions are implemented and attempting to call a W version will fail with an error code that indicates that function is unimplemented. On Windows NT/2000/XP/2003, both the A and W versions are implemented (however the operating system generally only internally implements the W version natively, and the A version is usually a translation thunk to the W version).

By adding the UNICOWS.LIB to the link command-line before KERNEL32.LIB, ADVAPI32.LIB, or any other supported Win32 system link library, the linker will resolve referenced symbols with the one provided by UNICOWS.LIB instead.

When a wide-character function is called for the first time at runtime, the function stub in UNICOWS.LIB first receives control and decides if it is running on a Windows 95/98/ME system:

  • If so, it dynamically loads the UNICOWS.DLL (if it hasn't been loaded yet) and passes control to the corresponding thunking stub in there. The thunking stub translates the wide-character arguments into ANSI strings and then invokes the native A version from the OS, and then translates any returned strings back into wide-character format.
  • If the OS natively supports the W version (i.e. Windows NT/2000/XP/2003), then the function stub updates the in-memory import table so that future calls will directly invoke the native W version without any more overhead.

Because of this technique, when an application is linked against MSLU, only Windows 95/98/ME systems will need the UNICOWS.DLL at runtime, and on all other operating systems there is only a slight performance penalty for the first function call.

A common problem encountered occurs when some updaters and uninstallers rename or delete the file oledlg.dll, preventing the operating system from loading unicows.dll. This results in applications, such as OpenOffice.org, reporting that "Application cannot start because one of the required libraries cannot be found." This occurs even if unicows.dll is installed in the system.

Read more about this topic:  Microsoft Layer For Unicode

Famous quotes containing the word works:

    I divide all literary works into two categories: Those I like and those I don’t like. No other criterion exists for me.
    Anton Pavlovich Chekhov (1860–1904)