WineHQ
WineHQ

Chapter 5. Building Winelib DLLs

5.1. Introduction

For one reason or another you may find yourself with a Linux library that you want to use as if it were a Windows DLL. There are various reasons for this including the following:

  • You are porting a large application that uses several third-party libraries. One is available on Linux but you are not yet ready to link to it directly as a Linux shared library.

  • There is a well-defined interface available and there are several Linux solutions that are available for it (e.g. the ODBC interface in Wine).

  • You have a binary only Windows application that can be extended through plugins, such as a text editor or IDE.

The process for dealing with these situations is actually quite simple. You need to write a spec file that will describe the library interface in the same format as a DLL (primarily what functions it exports). Also you will want to write a small wrapper around the library. You combine these to form a Wine built-in DLL that links to the Linux library. Then you modify the DllOverrides in the wine configuration to ensure that this new built-in DLL is called rather than any windows version.

In this section we will look at two examples. The first example is extremely simple and leads into the subject in "baby steps". The second example is the ODBC interface proxy in Wine. The files to which we will refer for the ODBC example are currently in the dlls/odbc32 directory of the Wine source.

The first example is based very closely on a real case (the names of the functions etc. have been changed to protect the innocent). A large Windows application includes a DLL that links to a third-party DLL. For various reasons the third-party DLL does not work too well under Wine. However the third-party library is also available for the Linux environment. Conveniently the DLL and Linux shared library export only a small number of functions and the application only uses one of those.

Specifically, the application calls a function:

signed short WINAPI MyWinFunc (unsigned short a, void *b, void *c,
        unsigned long *d, void *e, int f, char g, unsigned char *h);
and the linux library exports a corresponding function:
signed short MyLinuxFunc (unsigned short a, void *b, void *c,
        unsigned short *d, void *e, char g, unsigned char *h);