COVER STORY

Running Windows Programs with the Wine API PRACTICAL WINE

The Wine compatibility layer lets users run Windows programs. Unfortunately, configuring Wine is anything but trivial, and it helps if you enjoy experimenting. BY JOACHIM VON THADDEN

inux offers a number of options achieve just 50 to 80 percent of its nor- As there is a lot of redundancy in the for users who need to run an mal native performance, even with API, one might suspect that Microsoft Loccasional Windows program. increased static RAM memory use by the has actually lost track of the many thou- You can emulate a complete machine guest . sands of system calls and their extremely using an application such as VMware or An alternative to emulation is simply complex calling parameters. Addition- Qemu, or you can simulate a machine to provide Windows libraries for the ally, some functions are tailored to suit subset with Win4Lin. These solutions Linux system. In theory, this approach the Windows environment and make work quite well but also have some would allow the program to run in many assumptions about the underlying drawbacks: for one thing, users need to Linux. Unfortunately, this approach is system. For example, the Linux filesys- buy both the emulation environment complicated. First, the Windows tem is massively different from the Win- and the operating system, both of which functions, or so called API (Application dows filesystem. To mitigate this issue, it take up valuable space on the host Programming Interface), is not ade- would be useful to have the ability to machine. Emulation also taxes perfor- quately documented. And in many use the original Windows libraries. Of mance and soaks up memory. An aver- cases, programs written by Microsoft, in course, this means owning a Windows age program running in an emulator will particular, call undocumented functions. license, but most people have one any-

30 ISSUE 57 AUGUST 2005 WWW.LINUX - MAGAZINE.COM Wine COVER STORY

install, typing rpm -e wine should remove the offending version. On Fedora, the Prelink security mechanism, which stores prelinked versions of all system libraries, can cause a few issues. If you do not want to disable Prelink completely, first become root, and then, after installing Wine, delete the pre- linked libraries as follows:

killall prelink;prelink -uav; U rm /etc/prelink.cache; ldconfig

As Fedora’s Prelinking mechanism checks the libraries every 24 hours, the system will be returned to a safe state after 24 hours at the latest. If you are in a hurry, you can call the prelink cron script to reenable the mechanism:

killall prelink;U /etc/cron.daily/prelink

Figure 1: The rewards – complex Windows programs like Microsoft Word show good perfor- The Wine packages supplied with mance on Linux. Debian have gained a certain degree of notoriety for being poorly maintained way, so why not do something useful ages always use the release date as their and highly unpredictable. Debian users with it? version number. The October 2004 will want to deinstall any Wine packages The open source Wine project pro- release is extremely stable and gives me they discover, then change repository vides programming functionality and all the functionality I need. The versions and install the original packages from also integrates original libraries. The released since then have been highly Wine headquarters, as described at [3]. recursive acronym “Wine,” which stands experimental and do not lend them- for “Wine is not an emulator,” expresses selves to productive use. The latest ver- At the Wine Lodge – Wine’s what Wine truly is: not an operating sys- sion at this time of writing, 20050419, Directory System tem emulator, but a compatibility layer. looks more promising, but it refuses to Wine stores a user’s configuration and After a long development period, and cooperate with Microsoft Word. working files along with that user’s Win- with support from commercial enter- Fortunately, installing Wine is now dows programs below the user directory prises, Wine has now reached a stage of child’s play. Long-winded build and in the .wine subdirectory. Be careful if development that allows users to run an install processes are a thing of the past you log on as root. Just as Linux system amazingly large number of Windows for most distributions, as the official users should only log on as root to per- programs on Linux. This article takes a Wine Site has matching, and well main- form administrative chores, Wine users practical look at how to use Wine. tained, packages for Suse, Red Hat, should never use privileged accounts. Fedora, Debian, Mandrake, Slackware, For one thing, Windows programs are Installing Wine and even FreeBSD [1]. Older packages not exactly renowned for their security As Wine is subject to rapid development are also available [2]. After downloading and might compromise your system: for cycles, the version you use is critical. It the package, users with RPM-based dis- another, system calls that might other- does not make much sense to go for the tributions can simply become root and wise fail could work for the root user, latest version; in fact, I would suggest give the following command and this makes program behavior unpre- adopting a conservative approach and dictable. keeping a working version. Restrict rpm -Uvh wine-200xxxxx-* You will need a new Wine directory to experiments with new systems. complete the installation steps; if you The Wine version that I use myself, to install Wine on their systems. If a pre- have a pre-existing Wine directory, you 20041019, is not the latest. Wine pack- vious version gets in the way of the should rename it just to be on the safe

Advertisment

31 COVER STORY Wine

side. Initializing a new directory is quite Wine uses links below the ~/.wine/ sion setting is the setting for which the simple; just type wine at the console. dosdevices directory to provide the drive Wine API has the most functionality. This places the config configuration file, letters that Windows expects. The links The most powerful switch-box is and the Windows registry database, have exactly the names that Windows located below [DllOverrides] (Listing 3 which will store files with the reg suffix, programs expect of drive letters, that is, line 6). This is where you specify which directly below the ~/.wine directory. c:, d: and so on. Thus, the c subdirectory built-in Wine libraries you will be using More recent Wine versions do not create maps the Windows C: drive within the and which you will be replacing with the a config file. The following command: Linux filesystem tree, and this is where original Windows versions. These set- the beginnings of a typical collection tings can be prioritized; for example, cp /usr/share/doc/wine-U of Windows files and subdirectories specifying "native, builtin" indicates that 20041019/samples/config ~/U appears when you launch Wine for the Wine should search for a native library .wine first time. c/windows has a few symbolic first. If this library is not available, the links to programs such as regedit.exe or Wine copy is used. To use the original copies a template file. Incidentally, Wine notepad.exe; these programs are part of Windows DLL, you need to store it in does not support the original Windows the Wine package and should work the simulated Windows filesystem tree Registry file. Instead, Wine uses a clear- without any additional configuration. below windows/system or in the direc- text format, storing the system and user To test this, let’s call tory that contains the application you Registry hives in the system.reg and user. will be launching. However, not all DLLs reg files. As programs do not typically wine notepad are really appropriate or useful. For access the Registry directly, but take the example, the Windows kernel, user sys- recommended approach via system calls, This should launch our first program on tem, and graphical subsystem are this is a good way of making the Registry Wine. Some Wine packages install these located in the DLLs kernel.dll, user.dll, database easier for humans and programs as hard links in the Linux file- and gdi.dll, and can’t be used with machines to read and modify. system tree, allowing users to simply call Wine. The same thing applies to the 32- Notepad to launch the application. bit counterparts, kernel32.dll, user32.dll, and gdi32.dll. Low level DLLs, most Simple Configuration drivers, and VXD files are similarly The config file handles the Wine config- useless. uration. The structure of the config file is quite simple; just like a Windows .ini DLLs file, the config file comprises group DLLs are your best bet; names in square brackets, followed by some of them are available off the Inter- "Key" = "Value" pairs. In contrast to net [4] or from Microsoft. Avoid Win- Windows, both keys and values need to dows XP libraries, as they more or less be quoted, and comments are indicated never provide error-free service. Even by semicolons. The group order is not with Win98 DLLs, caution is recom- important. mended. Some work fine with some The [wine] group (Listing 1) contains applications, but the built-in Wine ver- a number of basic parameters that gov- sion performs better with others. In ern the filesystem structure and access many cases, Wine can leverage the so to the Linux system resources. You might called controls, that is, DLLs that provide like to set the "ShowDirSymlinks" and "ShowDotFiles" parameters to 1 here, to Listing 1: config Part 1 allow Windows file displays to show you 01 [wine] all the files on your Linux system. For example, hiding symlinks can mean 02 "GraphicsDriver" = "x11drv"; wasting a lot of time searching for files. (x11drv, ttydrv) You can leave all the other parameters as 03 "ShowDotFiles" = "1" is. 04 "ShowDirSymlinks" = "1" The [Version] section in Listing 2 05 "Path" = "c:\\windows;c:\\ allows users to modify the behavior of windows\\system" the Wine libraries. The "Windows" key can assume almost any value you like 06 "Windows" = "c:\\windows" for Windows versions between Windows 07 "System" = "c:\\windows\\ 3.0 and the latest Windows 2003. And system" this is important for a number of appli- 08 "Temp" = "t:\\" cations. However, most applications will 09 "Profile" = "c:\\windows\\ Figure 2: Wine is known to work with a vari- run best if you select "win98" for this Profiles\\Administrator" ety of Windows applications. parameter. Also, this Windows 98 ver-

32 ISSUE 57 AUGUST 2005 WWW.LINUX - MAGAZINE.COM Advertisment COVER STORY Wine

form elements such as input fields or the recommended mode for games, driver for sound output. For KDE users, dialog boxes, commctrl.dll and commdlg. which tend to switch graphics modes the correect driver is "winearts.drv". dll and their 32-bit counterparts; the frequently. And if a game crashes, this Not all of these drivers are well imple- same thing applies to the OLE DLLs that can leave the computer in the selected mented. And for sound output in partic- provide COM port functionality without graphics mode. The various members of ular, you may need to resort to "wineoss. the software installation crashing. As the the Windows Install Shield family also drv", assuming you disable sound out- whole thing is so complicated, Wine tend to grab the whole desktop and put for all your other programs prior to allows users to specify the DLL settings interrupt anything else going on there. making this selection to avoid conflicts. on a program-by-program basis, but Some sections allow individual configu- This warning particularly applies to the more of that later. WineHQ has notes on rations for the X11 driver, but again, I KDE and Gnome sound services artsd DLL issues and information on many will be looking at the subject in more and esd. common Windows DLLs at [5]. And you depth later on. The subsequent sections handle appli- can easily check the status of the Wine The other settings in this section con- cation defaults. [AppDefaults\\ library implementation at [6]. trol accelerated graphics modes, so you \\x11drv] defines the should be fine with the defaults; the graphic output settings for a specific DLL Overrides same thing goes for the font, I/ O port, program. You can use an optional Some components installed by Office or and other sections. The installation [AppDefaults\\\\DllOver- other programs can be a real pain. These packages take care of distribution spe- rides] to set up DLL defaults that will debuggers, which pop up whenever an cific settings. take priority over the settings in the application crashes, can make life a mis- matching generic sections. This allows ery. mdm.exe in the windows/ system Sound Settings you to demote Install Shield to a win- directory is a typical example. Thank Things start to liven up again in the dow, or prevent Quicktime Player 5 from goodness you can disable this kind of "WinMM" section, which handles sound using DirectDraw. application in the DLLOverrides section: output. You need to enable the right The documentation at [7] gives you for example: Listing 3: config, Part 2 "*mdm.exe" = "builtin" 01 [Version] 16 "d3d8" = 02 ; Windows version to imitate ( "builtin";Hardware related means search for this component in the win95,win98,winme,nt351,nt40,w 17 "d3d9" = Wine library collection. And because in2k,winxp,win2k3,w "builtin";Hardware related this program does not exist in the col- lection, it can’t run. 03 "Windows" = "win98" 18 [...] 04 ;"DOS" = "6.22" 19 "msi" = "native" Graphical Subsystem 05 20 "ole32" = "native" The following group [x11drv] (Listing 4) 06 [DllOverrides] 21 "odbc32" = "native, describes the properties of Wine’s graph- builtin" ical subsystem, which converts Win- 07 ; Some native dlls won't work, dows API calls to X11 on the Unix oper- so leave these builtin. 22 ating system. The "Managed” and 08 ; Do not modify these lines. 23 ; some spy or definitely not "Desktop" settings are of interest. A 09 "advapi32" = working programs we don't like value of "Y" for the former tells the X11 "builtin";Native version won't to be started window manager to handle Windows work 24 "*autorun.exe" = program windows; a setting of "N" 10 "avicap32" = "native,builtin" means that Wine will handle this. The "builtin";Hardware related 25 "*ctfmon.exe" = "builtin" advantage of allowing the window man- ager to do this job is the improved inte- 11 "capi2032" = 26 "*ddhelp.exe" = "builtin" gration with the desktop windowing sys- "builtin";Completely 27 "eMusicClient.exe" = "builtin" implemented tem. If you allow Wine to handle win- 28 "*findfast.exe" = "builtin" dow dressing, you get the typical Win- 12 "comctl32" = 29 "icwconn1.exe" = "builtin" dows look & feel instead. In many cases, "builtin";Native version cause ;Prevent from loading ICW even programs will only run in this mode. bugs. if registry key Setting “Y” as the default is a good idea 13 "comdlg32" = 30 in most cases. "builtin";thunk The "Desktop" parameter allows a pro- 31 ; default for all other dlls 14 "crtdll" = gram to run in its own desktop window; and "builtin";Completely you can specify the size, such as implemented 32 "*" = "native, builtin" 800x600. This makes sense if the pro- 33 ;"*" = "builtin, native" gram breaks your desktop or insists on 15 "ctl3d32" = running in the foreground. This is also "builtin";thunk

34 ISSUE 57 AUGUST 2005 WWW.LINUX - MAGAZINE.COM Wine COVER STORY

many more useful guidelines on Wine fashion. not use Registry keys are even more use- parameters, configuration, and fine tun- Many programs use Install Shield. ful; Lotus Notes is an example. Although ing. Unfortunately, Microsoft has not seen fit the installer will not run in Wine, you Experts will prefer the manual to specify a clear cut installation scheme can install on Windows and then simply approach to Wine configuration; that is, thus far, in contrast to the schemes intro- copy version 6.51 of Notes to the right they will prefer editing the configuration duced to Linux a while back such as place in your Wine filesystem tree. file. Newcomers may prefer a conve- DPKG or RPM. This means that installers Programs that prompt you for a CD, or nient, GUI-based tool. winesetuptk sup- are some of the biggest obstacles to to insert the next floppy disk during the ports simple editing, or generation of the Wine, and they can cause issues with installation or later, can prove difficult .wine/config files. more complex programs. for inexperienced users. Of course, you Unfortunately, the tool has not been If you have a program that you can’t need to mount the CD in Linux, how- maintained and thus uses some obsolete install for love or money, you might like ever, you must prevent the installer from configuration options. A new tool titled to install the program under Windows accessing the CD in the mount directory, winecfg is under development but not 98 first. Make sure you back up, or bet- as this attempt to access the CD will lock finished at this time of writing. And this ter still, export the Registry before you the drive, preventing it from being leaves you with the option of manual attempt the installation. After installing unmounted when you need to swap configuration, one of the Wine-based the required program, copy the program disks. If you are aware of this problem, Winetools, or Crossover Office. directory to the appropriate directory you should have no difficulty responding below ~/.wine, export the Windows to a change disk prompt by unmounting Ready, steady, go! Registry again, and compare the results. the CD at the console, changing the CD, One of the most important commands You will need to run the Wine regedit and mounting the next CD. for daily use of Wine is the Windows tool to modify any keys that have Daily use has shown that some pro- system reboot. Fortunately, Wine helps changed. In most cases, an installation grams need to be launched from within you avoid a genuine reboot. Entering will introduce new DLLs, and again you their program directories to perform will need to copy these DLLs to your well. Some programs do not take kindly wineboot Wine directory. With a bit of luck, the to users switching virtual desktops at will initiate the boot process in Windows program should run. Programs that do runtime; in fact, they may hang and take

Advertisment

WWW.LINUX - MAGAZINE.COM ISSUE 57 AUGUST 2005 35 COVER STORY Wine

a lot of reanimation. This often means DOS programs. restarting the application. Programs that do not exit gracefully can leave compo- wine wcmd nents running in memory; typing ps -ax|grep wine will give you more details. launches the com- mand interpreter, wineserver -kill where you can run DOS pro- kills any and all current instances of grams, but don’t Wine. Figure 3: The Uninstaller takes you to a selection of deinstall tools. set your sights too Programs that hog the whole screen high. If you want and mess it up are also a nuisance. The ing command: to run a DOS pro- best approach to handling these progra- gram, you might prefer to use or ms in Wine is to bundle them off into a wine control [8]. This is particularly true of window when they are launched, as DOS games. described previously: simply remove the launches the tool and gives you access comment tag from the Desktop" = to the installed system configuration Working with Hardware "1024x768 line to run all of your Win- components. You can also deinstall pro- Wine provides an emulation layer for dows applications in windows. Or better grams using the Control Center: binary files belonging to another operat- still, create an application-specific sec- ing system. This involves a few restric- tion in the configuration to run just the wine uninstaller tions that make some applications unus- offending program in a window. able, or virtually unusable. For example, The Control Center helps handle pro- launches an applet that takes you to a applications that need a specific hard- grams that are configured via the Win- selection of registered deinstall pro- ware driver will not run. In fact, merely dows System Settings. Typing the follow- grams. Wine has restricted support for attempting to install a Windows hard-

Listing 4: config, Part 3 INFO

01 [x11drv] present [1] “Wine Headquarters”: http:// www. 02 ; Number of colors to allocate 20 "UseXRandR" = "N" winehq. org/ site/ download from the system palette 21 ... [2] Wine download site: http:// prdownloads. sourceforge. net/ wine 03 "AllocSystemColors" = "100" 22 [3] Debian package download: http:// 04 ; Use a private color map 23 [WinMM] www. winehq. org/ site/ download-deb 05 "PrivateColorMap" = "N" 24 "Drivers" = "wineoss.drv" [4] Source for Windows DLLs: 06 ; Favor correctness over speed ; default for most common http:// www. dll-files. com in some graphics operations configurations [5] DLL topics: http:// www. winehq. com/ 07 "PerfectGraphics" = "N" 25 ;"Drivers" = "winearts.drv" site/ docs/ wine-devel/ arch-dlls [6] Library implementation status: http:// 08 ; Color depth to use on ; for KDE www. winehq. com/ site/ status_dlls multi-depth screens 26 ;"Drivers" = "winealsa.drv" [7] Wine documentationhttp:// www. ; for ALSA users 09 ;;"ScreenDepth" = "16" winehq. org/ site/ documentation 27 ;"Drivers" = "winejack.drv" 10 ; Allow the window manager to [8] Dosbox: manage created windows ; for Jack sound server http:// dosbox. sourceforge. net 11 "Managed" = "Y" 28 ;"Drivers" = "winenas.drv" [9] Applications that run on Wine: ; for NAS sound system http:// appdb. winehq. org 12 ; Use a desktop window of 640x480 for Wine 29 ;"Drivers" = "wineaudioio.drv" [10] Frank’s Corner, alternative Wine site: ; for Solaris machines http:// frankscorner. org 13 ;"Desktop" = "1024x768" 30 ;"Drivers" = "" ; [11] Debug documentation: 14 ; Use XFree86 DGA extension if http:// winehq. org/ site/ docs/ present 31 wine-user/ x1824#AEN1826 15 ; (make sure /dev/mem is 32 [AppDefaults\\_INS0432._MP\\ [12] Wine forums for your questions: accessible by you !) x11drv] http:// www. winehq. org/ site/ forums [13] Crossover Office: 16 "UseDGA" = "N" 33 "Desktop" = "1024x768" http:// www. codeweavers. com 17 ; Use XVidMode extension if 34 [14] Cedega by Transgaming: present 35 [AppDefaults\\QuickTimePlayer. http:// www. transgaming. com exe\\DLLOverrides] 18 "UseXVidMode" = "Y" [15] Transgaming installation packages: 19 ; Use XRandR extension if 36 "ddraw" = "" http:// www003. portalis. it/ 115/

36 ISSUE 57 AUGUST 2005 WWW.LINUX - MAGAZINE.COM Wine COVER STORY

ware driver is doomed to failure, as the an application running in Wine crashes. Future way the two operating systems handle If you are not interested in investigating hardware is vastly different. Some pro- the whys and wherefores, you can sim- There are a few things you need to take grams that required direct hard disk or ply quit. If you prefer to analyze the care of before you can put Wine to pro- CD ROM access will run despite this. problem, you can type bt to request a ductive use. First of all, you should be Wine gives you a direct access mode to backtrace. aware that only 30 percent of all Win- support this, allowing such unlikely can- The best approach with misbehaving dows applications will run successfully didates as the downloadable version of programs is to try out the various set- under Wine. Don’t demand too much Nero Burning Rom to run, whereas Clon- tings for the Windows version first. from the system; it is not designed to be eCD provides its own drivers for drive Some programs are very choosy about a replacement for Windows; if you are access; drivers that, unfortunately, will the path from which you launch them. looking for one, the obvious answer is not talk to Wine. No matter what appli- Again, you might like to try launching Linux, with its amazing collection of use- cation you are thinking of running, you the program from its own directory, ful and free applications. What Wine might like to check out the application providing a complete Windows path, or gives you is the chance to run important databases at [9] and [10] to find out if trying the Linux path (Listing 5). Even Windows applications for which you do someone has already done the hard though the examples in these paths are not have a Linux replacement, thus work or possibly created an installation supposed to be equivalent, a Windows allowing a gradual migration. If you report or guide. program might not see things the way make heavy use of Office products, you will definitely appreciate the ability to you or I do. continue using these products and try- DirectX Your choice of window manager might ing out something new at the same Games that rely on DirectX may or may also cause a few issues. Changing the time. The commercial variants, Cedega not run well. Again, the Internet sources Managed and Desktop parameters can for games and CrossOver Office for will tell you more. Wine emulates the work miracles in this case, especially if a Office products, are definitely valuable behavior of DirectX 8, and that gives you program runs but fails to draw the pro- contributions, as they provide support a genuine chance of running DirectX gram window correctly. and help keep development work up to compatible games. On the downside, It can also make sense to specify speed. In a commercial environment, anything that uses copy protection will debugging parameters when launching a you will find it difficult to replace them. not run on Wine. These mechanisms are program: WINEDEBUG="+loaddll" so low-level that they are doomed to fail. wine program_path will launch a pro- Whatever you do, do not install the orig- gram and tell you whether the DLLs the additional parameters that allow users to inal DirectX. It won’t work, but it might program uses are native or built-in. This output specific runtime environment completely destroy your current Wine information allows you to identify DLLs components. directory setup. with an inadequate implementation in If you're looking for help with Wine, Wine and to replace these DLLs with the the Wine-Users mailing list archives at Debugging native Windows equivalents, which in [12] have a number of discussion Every Wine user will make the acquain- turn, hopefully, will allow you to run the threads with questions and answers on tance of the winedbg debugger sooner or desired program. The Wine Debug docu- Wine issues. And, of course, new ques- later. The debugger appears whenever mentation at [11] quotes a number of tions are welcome. ■

Listing 5: Alternative Alternatives: CrossOver Office and Cedega Program Launchers Wine has given rise to a number of lation sessions, and hours spent brows- 01 wine "c:\\program files\\ major commercial products, all of which ing documentation on the Web, can be a microsoft office\\office\\ have drawn on the Wine codebase thing of the past, for a low asking price winword.exe" before specializing on specific features, of just US$ 40 or EUR 40. which they have then given back. Code- Transgaming's Cedega [14] specializes in 02 Weavers’ CrossOver Office [13] special- using Wine as a gaming platform and 03 wine "~/.wine/c/Program Files/ izes in supporting major Office applica- has pushed development of the DirectX Microsoft Office/Office/ tions, and it has to be said that Code- emulation. Special copy protection code WINWORD.EXE" Weavers have done a great job. The fact allows users to run copy protected 04 that CodeWeavers give their patches games. The software is available as a back to the Wine developers has allowed subscription version for US$ 5 or EUR 5 05 cd ~/.wine/c/Program Files/ Wine to really grow over the last 12 per month with a minimum subscription Microsoft Office/Office; wine months. CrossOver Office gives you the of three months. With the exception of WINWORD.EXE latest Wine libraries, a very convenient the copy protection code, the source 06 installer for the applications it supports, code for Cedega is available, and this 07 cd ~/.wine/c/Program Files/ complete desktop integration, and sup- means that users can build Cedega Microsoft Office/Office; wine port from CodeWeavers. The disadvan- themselves. Ready-made installation "c:\\program files\\microsoft tages of having to test new Wine ver- packages for various distributions are sions, time-consuming, marathon instal- available from [15]. office\\office\\winword.exe"

WWW.LINUX - MAGAZINE.COM ISSUE 57 AUGUST 2005 37