<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML
><HEAD
><TITLE
>Winelib User's Guide</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.79"></HEAD
><BODY
CLASS="BOOK"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><DIV
CLASS="BOOK"
><A
NAME="INDEX"
></A
><DIV
CLASS="TITLEPAGE"
><H1
CLASS="TITLE"
><A
NAME="AEN2"
>Winelib User's Guide</A
></H1
><HR></DIV
><DIV
CLASS="TOC"
><DL
><DT
><B
>Table of Contents</B
></DT
><DT
><A
HREF="#WINELIB-INTRODUCTION"
>Winelib Introduction</A
></DT
><DD
><DL
><DT
><A
HREF="#WINELIB-WHATIS"
>What is Winelib?</A
></DT
><DT
><A
HREF="#WINELIB-REQUIREMENTS"
>System requirements</A
></DT
><DT
><A
HREF="#WINELIB-GETTING-STARTED"
>Getting Started</A
></DT
><DD
><DL
><DT
><A
HREF="#WINEMAKER-INTRODUCTION"
>Winemaker introduction</A
></DT
><DT
><A
HREF="#WINEMAKER-TEST"
>Test Drive</A
></DT
><DT
><A
HREF="#WINEMAKER-GUIDE"
>Step by step guide</A
></DT
></DL
></DD
></DL
></DD
><DT
><A
HREF="#PORTABILITY-ISSUES"
>Portability issues</A
></DT
><DD
><DL
><DT
><A
HREF="#UNICODE"
>Unicode</A
></DT
><DT
><A
HREF="#C-LIBRARY"
>C library</A
></DT
><DT
><A
HREF="#PORTING-COMPILING"
>Compiling Problems</A
></DT
></DL
></DD
><DT
><A
HREF="#WINELIB-TOOLKIT"
>The Winelib development toolkit</A
></DT
><DD
><DL
><DT
><A
HREF="#WINEMAKER"
>Winemaker</A
></DT
><DD
><DL
><DT
><A
HREF="#VC-PROJECTS"
>Support for Visual C++ projects</A
></DT
><DT
><A
HREF="#SOURCE-ANALYSIS"
>Winemaker's source analysis</A
></DT
><DT
><A
HREF="#INTERACTIVE"
>The interactive mode</A
></DT
><DT
><A
HREF="#MAKEFILE"
>The Makefile files</A
></DT
></DL
></DD
><DT
><A
HREF="#WRC"
>Compiling resource files: WRC</A
></DT
><DT
><A
HREF="#WMC"
>Compiling message files: WMC</A
></DT
><DT
><A
HREF="#SPEC-FILE"
>The Spec file</A
></DT
><DD
><DL
><DT
><A
HREF="#SPEC-INTRO"
>Introduction</A
></DT
><DT
><A
HREF="#SPEC-COMPILING"
>Compiling it</A
></DT
><DT
><A
HREF="#SPEC-REFERENCE"
>More details</A
></DT
></DL
></DD
><DT
><A
HREF="#LINKING"
>Linking it all together</A
></DT
></DL
></DD
><DT
><A
HREF="#MFC"
>Dealing with the MFC</A
></DT
><DD
><DL
><DT
><A
HREF="#MFC-INTRODUCTION"
>Introduction</A
></DT
><DT
><A
HREF="#MFC-LEGAL-ISSUES"
>Legal issues</A
></DT
><DT
><A
HREF="#MFC-COMPILING"
>Compiling the MFC</A
></DT
></DL
></DD
><DT
><A
HREF="#BINDLLS"
>Building WineLib DLLs</A
></DT
><DD
><DL
><DT
><A
HREF="#BINDLLS-INTRO"
>Introduction</A
></DT
><DT
><A
HREF="#BINDLLS-SPEC"
>Writing the spec file</A
></DT
><DT
><A
HREF="#BINDLLS-WRAPPER"
>Writing the wrapper</A
></DT
><DT
><A
HREF="#BINDLLS-BUILDING"
>Building</A
></DT
><DT
><A
HREF="#BINDLLS-INSTALLING"
>Installing</A
></DT
><DT
><A
HREF="#BINDLLS-FILENAMES"
>Converting filenames</A
></DT
></DL
></DD
></DL
></DIV
><DIV
CLASS="CHAPTER"
><HR><H1
><A
NAME="WINELIB-INTRODUCTION"
></A
>Winelib Introduction</H1
><DIV
CLASS="SECT1"
><H2
CLASS="SECT1"
><A
NAME="WINELIB-WHATIS"
>What is Winelib?</A
></H2
><P
>        Winelib is a development toolkit which allows you to compile your
        Windows applications on Unix.
      </P
><P
>        Most of Winelib's code consists of the Win32 API implementation.
        Fortunately this part is 100 percent shared with Wine. The remainder
        consists of Windows compatible headers and tools like the resource
        compiler (and even these are used when compiling Wine).
      </P
><P
>        Thanks to the above, Winelib supports most C and C++ 32bit source code,
        resource and message files, and can generate graphical or console
        applications as well as dynamic libraries.
      </P
><P
>        What is not supported is 16bit source code as the types it depends on
        (especially segmented pointers) are not supported by Unix compilers.
        Also missing are some of the more exotic features of Microsoft's
        compiler like native COM support and structured exception handling.
        So you may need to perform some modifications in your code when
        recompiling your application with Winelib. This guide is here to help
        you in this task.
      </P
><P
>        What you gain by recompiling your application with Winelib is the
        ability to make calls to Unix APIs, directly from your
        Windows source code. This allows for a better integration with the
        Unix environment than is allowed by running an unmodified Windows
        application running in Wine. Another benefit is that a Winelib
        application can relatively easily be recompiled on a non-Intel
        architecture and run there without the need for a slow software
        emulation of the processor.
      </P
></DIV
><DIV
CLASS="SECT1"
><HR><H2
CLASS="SECT1"
><A
NAME="WINELIB-REQUIREMENTS"
>System requirements</A
></H2
><P
>        The requirements for Winelib are similar to those for Wine.
      </P
><P
>        Basically if you can run Wine on your computer then you can run
        Winelib. But the converse is not true. You can also build Winelib
        and Winelib applications on platforms not supported by Wine,
        typically platforms with a non i386 processor. But this is still
        pretty much uncharted territory. It would be more reasonable to
        target one of the more mundane i386-based platforms first.
      </P
><P
>        The main difference is that the compiler becomes much more important.
        It is highly recommended that you use gcc, g++, and the GNU binutils. 
        The more recent your gcc compiler the better.
        For any serious amount of code you should not consider anything older
        than gcc 2.95.2. The latest gcc snapshots contain some useful bug
        fixes and much better support for anonymous structs and unions. This
        can help reduce the number of changes you have to do in your code but
        these are not stable releases of the compiler so you may not want to
        use them in production.
      </P
></DIV
><DIV
CLASS="SECT1"
><HR><H2
CLASS="SECT1"
><A
NAME="WINELIB-GETTING-STARTED"
>Getting Started</A
></H2
><DIV
CLASS="SECT2"
><H3
CLASS="SECT2"
><A
NAME="WINEMAKER-INTRODUCTION"
>Winemaker introduction</A
></H3
><P
>          So what is needed to compile a Windows application with Winelib?
          Well, it really depends on the complexity of your application but
          here are some issues that are shared by all applications:
        </P
><P
></P
><UL
><LI
><P
>              the case of your files may be bad. For example they could be
              in all caps: <TT
CLASS="FILENAME"
>HELLO.C</TT
>. It's not very nice to
              work with and probably not what you intended.
            </P
></LI
><LI
><P
>              then the case of the filenames in your include statements may be
              wrong: maybe they include <TT
CLASS="FILENAME"
>Windows.h</TT
> instead
              of <TT
CLASS="FILENAME"
>windows.h</TT
>.
            </P
></LI
><LI
><P
>              your include statements may use '\' instead of '/'. '\' is not
              recognized by Unix compilers while '/' is recognized in both
              environments.
            </P
></LI
><LI
><P
>              you will need to perform the usual Dos to Unix text file conversion
              otherwise you'll get in trouble when the compiler considers that
              your '\' is not at the end of the line since it is followed by a
              pesky carriage return.
            </P
></LI
><LI
><P
>              you will have to write new makefiles.
            </P
></LI
></UL
><P
>          The best way to take care of all these issues is to use winemaker.
        </P
><P
>          Winemaker is a perl script which is designed to help you bootstrap
          the conversion of your Windows projects to Winelib. In order to do
          this it will go analyze your code, fixing the issues listed above
          and generate straight Makefiles.
        </P
><P
>          Let's suppose that you are already in the top directory of your
          sources. Then converting your project to Winelib may be as simple
          as just running the three commands below (note the dot indicating
          current directory at the end of the first command):
        </P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>          $ winemaker --lower-uppercase .
          $ make
        </PRE
></TD
></TR
></TABLE
><P
>          But of course things are not always that simple which is why we have
          this guide at all.
        </P
></DIV
><DIV
CLASS="SECT2"
><HR><H3
CLASS="SECT2"
><A
NAME="WINEMAKER-TEST"
>Test Drive</A
></H3
><P
>          Before starting to work on a big project you may want to try to port a
          small application. The notepad application from the Wine source tree
          suits well for testing purposes. It can be found in the programs
          subdirectory. notepad is a simple application, but has a few C,
          header and resource files.
        </P
><P
>          Run <B
CLASS="COMMAND"
>make clean</B
> in the
          notepad source directory if it contains results of previous builds.
          Create a separate directory with name notepad2, so it won't conflict
          with the Wine copy of the application. Copy the sources of notepad
          (files *.c, *.h, *.rc) to this directory. Now run the commands,
          mentioned above from the notepad2 directory:
        </P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>          $ winemaker --lower-uppercase .
          $ make
        </PRE
></TD
></TR
></TABLE
><P
>          Notice how the build fails in a resource file
          (<TT
CLASS="FILENAME"
>Da.rc</TT
> at the time this was written).
          This is because for the time being, the Wine resource compiler
          (<B
CLASS="COMMAND"
>windres</B
>) can't cope with more than one
          resource file ending up in a given executable. To get around
          that limitation, the Wine developers have chosen to only have
          one master resource file per application, and include the
          other ones via <TT
CLASS="LITERAL"
>#include</TT
> statements in the
          master one. The included files do not
          <TT
CLASS="LITERAL"
>#include</TT
> the necessary files to be
          compilable on their own. You will need to do the same thing
          for now in your own Winelib port projects.
        </P
><P
>          To fix that problem, you will need to edit the list of
          resource files winemaker thought notepad used, and only keep
          the master resource file. To do so, open
          <TT
CLASS="FILENAME"
>notepad2/Makefile</TT
> in a text editor and
          search for an assignment to a variable with
          <TT
CLASS="LITERAL"
>RC_SRCS</TT
> as part of its name. It will likely
          be named <TT
CLASS="LITERAL"
>notepad2_exe_RC_SRCS</TT
>. There will
          be a list of resource files starting on the same line. Remove
          them all except <TT
CLASS="FILENAME"
>rsrc.rc</TT
> (this is the
          master one for notepad). Save your work.
        </P
><P
>          Now you're ready to continue at the same point the first
          <B
CLASS="COMMAND"
>make</B
> failed. Return to the notepad2
          directory and type:
        </P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>          $ make
        </PRE
></TD
></TR
></TABLE
><P
>          You are done! Now you can start the application as
          <B
CLASS="COMMAND"
>./notepad2</B
>.
        </P
><P
>          If you come across problems preparing and building this application
          this probably means that winemaker utility is broken by some changes
          in Wine. Try asking for help on <CODE
CLASS="EMAIL"
>&#60;<A
HREF="mailto:wine-devel@winehq.org"
>wine-devel@winehq.org</A
>&#62;</CODE
>
        </P
></DIV
><DIV
CLASS="SECT2"
><HR><H3
CLASS="SECT2"
><A
NAME="WINEMAKER-GUIDE"
>Step by step guide</A
></H3
><P
>          Let's retrace the steps above in more details.
        </P
><P
></P
><DIV
CLASS="VARIABLELIST"
><DL
><DT
><CODE
CLASS="OPTION"
>Getting the source</CODE
></DT
><DD
><P
>                First if you can try to get the sources together with the
                executables/libraries that they build. In the current state of
                winemaker having these around can help it guess what it is that
                your project is trying to build. Later, when it is able to
                understand Visual C++ projects, and if you use them, this will
                no longer be necessary. Usually the executables and libraries
                are in a <TT
CLASS="FILENAME"
>Release</TT
> or
                <TT
CLASS="FILENAME"
>Debug</TT
> subdirectory of the
                directory where the sources are. So it's best if you can
                transfer the source files and either of these directories to
                Linux. Note that you don't need to transfer the
                <TT
CLASS="FILENAME"
>.obj</TT
>, <TT
CLASS="FILENAME"
>.pch</TT
>,
                <TT
CLASS="FILENAME"
>.sbr</TT
> and other files that also reside in
                these directories; especially as they tend to be quite big.
              </P
></DD
><DT
><CODE
CLASS="OPTION"
>cd &#60;root_dir&#62;</CODE
></DT
><DD
><P
>                Then go to the root directory where are your source files.
                Winemaker can deal with a whole directory hierarchy at once so
                you don't need to go into a leaf directory, quite the contrary.
                Winemaker will automatically generate makefiles in each
                directory where one is required, and will generate a global
                makefile so that you can rebuild all your executables and
                libraries with a single <B
CLASS="COMMAND"
>make</B
> command.
              </P
></DD
><DT
><CODE
CLASS="OPTION"
>Making the source writable</CODE
></DT
><DD
><P
>                Then make sure you have write access to your sources. It may
                sound obvious, but if you copied your source files from a
                CD-ROM or if they are in Source Safe on Windows, chances are
                that they will be read-only.
                But Winemaker needs write access so that it can fix them. You
                can arrange that by running <B
CLASS="COMMAND"
>chmod -R u+w .</B
>.
                Also you will want to make sure that you have a backup copy of
                your sources in case something went horribly wrong, or more
                likely, just for reference at a later point. If you use a
                version control system you're already covered.
              </P
><P
>                If you have already modified your source files and you want
                to make sure that winemaker will not make further changes to
                them then you can use the --nosource-fix option to protect
                them.
              </P
></DD
><DT
><CODE
CLASS="OPTION"
>Running winemaker</CODE
></DT
><DD
><P
>                Then you'll run winemaker. Here are the options you will most
                likely want to use. For complete list of options see
                the winemaker man page.
              </P
><P
></P
><DIV
CLASS="VARIABLELIST"
><DL
><DT
><CODE
CLASS="OPTION"
>--lower-uppercase</CODE
>, <CODE
CLASS="OPTION"
>--lower-all</CODE
></DT
><DD
><P
>                      These options specify how to deal with files, and
                      directories, that have an 'incorrect' case.
                      <CODE
CLASS="OPTION"
>--lower-uppercase</CODE
> specifies they should
                      only be renamed if their name is all uppercase. So files
                      that have a mixed case, like 'Hello.c' would not be
                      renamed. <CODE
CLASS="OPTION"
>--lower-all</CODE
> will rename any
                      file. If neither is specified then no file or directory
                      will be renamed, almost. As you will see
                      <A
HREF="#RENAMING"
>later</A
> winemaker may
                      still have to rename some files.
                    </P
></DD
><DT
><CODE
CLASS="OPTION"
>--nobackup</CODE
></DT
><DD
><P
>                      Winemaker normally makes a backup of all the files in which
                      it does more than the standard Dos to Unix conversion.
                      But if you already have (handy) copies of these files
                      elsewhere you may not need these so you should use this
                      option.
                    </P
></DD
><DT
><CODE
CLASS="OPTION"
>--dll</CODE
>, <CODE
CLASS="OPTION"
>--console</CODE
></DT
><DD
><P
>                      These option lets winemaker know what kind of target you are
                      building. If you have the windows library in your source
                      hierarchy then you should not need to specify
                      <CODE
CLASS="OPTION"
>--dll</CODE
>. But if you have console executables
                      then you will need to use the corresponding option.
                    </P
></DD
><DT
><CODE
CLASS="OPTION"
>--mfc</CODE
></DT
><DD
><P
>                      This option tells winemaker that you are building an MFC
                      application/library.
                    </P
></DD
><DT
><CODE
CLASS="OPTION"
>-Dmacro[=defn]</CODE
>, <CODE
CLASS="OPTION"
>-Idir</CODE
>, <CODE
CLASS="OPTION"
>-Ldir</CODE
>, <CODE
CLASS="OPTION"
>-idll</CODE
>, <CODE
CLASS="OPTION"
>-llibrary</CODE
></DT
><DD
><P
>                      The <CODE
CLASS="OPTION"
>-i</CODE
> specifies a Winelib library to
                      import via the <A
HREF="#SPEC-FILE"
>spec file</A
>
                      mechanism. Contrast this with the <CODE
CLASS="OPTION"
>-l</CODE
>
                      which specifies a Unix library to link with. The other
                      options work the same way they would with a C
                      compiler. All are applied to all the targets found.
                      When specifying a directory with either
                      <CODE
CLASS="OPTION"
>-I</CODE
> or <CODE
CLASS="OPTION"
>-L</CODE
>, winemaker
                      will prefix a relative path with
                      <TT
CLASS="LITERAL"
>$(TOPDIRECTORY)/</TT
> so that it is valid
                      from any of the source directories. You can also use a
                      variable in the path yourself if you wish (but don't
                      forget to escape the '$'). For instance you could specify
                      <TT
CLASS="LITERAL"
>-I\$(WINELIB_INCLUDE_ROOT)/msvcrt</TT
>.
                    </P
></DD
></DL
></DIV
><P
>                So your command may finally look like:
                <TT
CLASS="LITERAL"
>winemaker --lower-uppercase -Imylib/include .</TT
>
              </P
></DD
><DT
><CODE
CLASS="OPTION"
>File renaming</CODE
></DT
><DD
><P
>                When you execute winemaker it will first rename files to bring
                their character case in line with your expectations and so that they can
                be processed by the makefiles. This later category implies that
                files with a non lowercase extension will be renamed so that the
                extension is in lowercase. So, for instance,
                <TT
CLASS="FILENAME"
>HELLO.C</TT
> will be renamed to
                <TT
CLASS="FILENAME"
>HELLO.c</TT
>. Also if a file or directory name
                contains a space or a dollar, then this
                character will be replaced with an underscore. This is because
                these characters cause problems with current versions of autoconf
                (2.13) and make (3.79).
              </P
></DD
><DT
><CODE
CLASS="OPTION"
>Source modifications and makefile generation</CODE
></DT
><DD
><P
>                winemaker will then proceed to modify the source files so that
                they will compile more readily with Winelib. As it does so it
                may print warnings when it has to make a guess or identifies a
                construct that it cannot correct. Finally it will generate the
                autoconf-based makefiles. Once all this is done you can review
                the changes that winemaker did to your files by using
                <B
CLASS="COMMAND"
>diff -uw</B
>. For instance:
                <B
CLASS="COMMAND"
>diff -uw hello.c.bak hello.c</B
>
              </P
></DD
><DT
><CODE
CLASS="OPTION"
>Running make</CODE
></DT
><DD
><P
>                This is a pretty simple step: just type <B
CLASS="COMMAND"
>make</B
>
                and voila, you should have all your executables and libraries.
                If this did not work out, then it means that you will have to
                read this guide further to:
                <P
></P
><UL
><LI
><P
>                      review the <TT
CLASS="FILENAME"
>Makefile</TT
> files to
                      adjust what winemaker thinks are the binaries you are
                      trying to build and which sources should be used for
                      each. See the <A
HREF="#SOURCE-ANALYSIS"
><I
>Winemaker's source analysis</I
></A
> section for some hints.
                    </P
></LI
><LI
><P
>                      fix the portability issues in your sources. See
                      <A
HREF="#PORTABILITY-ISSUES"
><I
>Portability issues</I
></A
> for more details.
                    </P
></LI
></UL
>
              </P
></DD
></DL
></DIV
></DIV
></DIV
></DIV
><DIV
CLASS="CHAPTER"
><HR><H1
><A
NAME="PORTABILITY-ISSUES"
></A
>Portability issues</H1
><DIV
CLASS="SECT1"
><H2
CLASS="SECT1"
><A
NAME="UNICODE"
>Unicode</A
></H2
><P
>	The <TT
CLASS="LITERAL"
>wchar_t</TT
> type has different standard
	sizes in Unix (4 bytes) and Windows (2 bytes). You need a
        recent gcc version (2.9.7 or later) that supports the
	<TT
CLASS="PARAMETER"
><I
>-fshort-wchar</I
></TT
> option to set the
	size of <TT
CLASS="LITERAL"
>wchar_t</TT
> to the one expected
	by Windows applications. 
      </P
><P
>        If you are using Unicode and you want to be able to use
        standard library calls (e.g. <TT
CLASS="FUNCTION"
>wcslen</TT
>,
        <TT
CLASS="FUNCTION"
>wsprintf</TT
>), then you must use
        the msvcrt runtime library instead of glibc. The functions in
        glibc will not work correctly with 16 bit strings.
      </P
></DIV
><DIV
CLASS="SECT1"
><HR><H2
CLASS="SECT1"
><A
NAME="C-LIBRARY"
>C library</A
></H2
><P
>        There are 2 choices available to you regarding which C library
        to use: the native glibc C library or the msvcrt C library.
      </P
><P
>        Note that under Wine, the crtdll library is implemented using
        msvcrt, so there is no benefit in trying to use it.
      </P
><P
>        Using glibc in general has the lowest overhead, but this is
        really only important for file I/O, as many of the functions
        in msvcrt are simply resolved to glibc.
      </P
><P
>        To use glibc, you don't need to make changes to your
        application; it should work straight away. There are a few
        situations in which using glibc is not possible:
      </P
><P
></P
><OL
TYPE="1"
><LI
><P
>            Your application uses Win32 and C library unicode
            functions.
          </P
></LI
><LI
><P
>            Your application uses MS specific calls like
            <TT
CLASS="FUNCTION"
>beginthread()</TT
>,
            <TT
CLASS="FUNCTION"
>loadlibrary()</TT
>, etc.
          </P
></LI
><LI
><P
>            You rely on the precise semantics of the calls, for
            example, returning <TT
CLASS="LITERAL"
>-1</TT
> rather than
            non-zero. More likely, your application will rely on calls
            like <TT
CLASS="FUNCTION"
>fopen()</TT
> taking a Windows path
            rather than a Unix one.
          </P
></LI
></OL
><P
>        In these cases you should use msvcrt to provide your C runtime
        calls.
      </P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>import msvcrt.dll</PRE
></TD
></TR
></TABLE
><P
>        to your applications <TT
CLASS="FILENAME"
>.spec</TT
> file. This
        will cause <B
CLASS="COMMAND"
>winebuild</B
> to resolve your c
        library calls to <TT
CLASS="FILENAME"
>msvcrt.dll</TT
>. Many simple
        calls which behave the same have been specified as
        non-importable from msvcrt; in these cases
        <B
CLASS="COMMAND"
>winebuild</B
> will not resolve them and the
        standard linker <B
CLASS="COMMAND"
>ld</B
> will link to the glibc
        version instead.
      </P
><P
>        In order to avoid warnings in C (and potential errors in C++)
        from not having prototypes, you may need to use a set of MS
        compatible header files. These are scheduled for inclusion
        into Wine but at the time of writing are not available. Until
        they are, you can try prototyping the functions you need, or
        just live with the warnings.
      </P
><P
>        If you have a set of include files (or when they are available
        in Wine), you need to use the <TT
CLASS="PARAMETER"
><I
>-isystem
        "include_path"</I
></TT
> flag to gcc to tell it to use your
        headers in preference to the local system headers.
      </P
><P
>        To use option 3, add the names of any symbols that you don't
        want to use from msvcrt into your applications
        <TT
CLASS="FILENAME"
>.spec</TT
> file. For example, if you wanted
        the MS specific functions, but not file I/O, you could have a
        list like:
      </P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>@ignore = ( fopen fclose fwrite fread fputs fgets )</PRE
></TD
></TR
></TABLE
><P
>        Obviously, the complete list would be much longer. Remember
        too that some functions are implemented with an underscore in
        their name and <TT
CLASS="FUNCTION"
>#define</TT
>d to that name in
        the MS headers. So you may need to find out the name by
        examining <TT
CLASS="FILENAME"
>dlls/msvcrt/msvcrt.spec</TT
> to get
        the correct name for your <TT
CLASS="FUNCTION"
>@ignore</TT
> entry.
      </P
></DIV
><DIV
CLASS="SECT1"
><HR><H2
CLASS="SECT1"
><A
NAME="PORTING-COMPILING"
>Compiling Problems</A
></H2
><P
>        If you get undefined references to Win32 API calls when
        building your application: if you have a VC++
        <TT
CLASS="FILENAME"
>.dsp</TT
> file, check it for all the
        <TT
CLASS="FILENAME"
>.lib</TT
> files it imports, and add them to
        your applications <TT
CLASS="FILENAME"
>.spec</TT
>
        file. <B
CLASS="COMMAND"
>winebuild</B
> gives you a warning for
        unused imports so you can delete the ones you don't need
        later. Failing that, just import all the DLLs you can find in
        the <TT
CLASS="FILENAME"
>dlls/</TT
> directory of the Wine source
        tree.
      </P
><P
>        If you are missing GUIDs at the link stage, add
        <TT
CLASS="PARAMETER"
><I
>-lwine_uuid</I
></TT
> to the link line.
      </P
><P
>        gcc is more strict than VC++, especially when compiling
        C++. This may require you to add casts to your C++ to prevent
        overloading ambiguities between similar types (such as two
        overloads that take int and char respectively).
      </P
><P
>        If you come across a difference between the Windows headers
        and Wine's that breaks compilation, try asking for help on
        <CODE
CLASS="EMAIL"
>&#60;<A
HREF="mailto:wine-devel@winehq.org"
>wine-devel@winehq.org</A
>&#62;</CODE
>.
      </P
></DIV
></DIV
><DIV
CLASS="CHAPTER"
><HR><H1
><A
NAME="WINELIB-TOOLKIT"
></A
>The Winelib development toolkit</H1
><DIV
CLASS="SECT1"
><H2
CLASS="SECT1"
><A
NAME="WINEMAKER"
>Winemaker</A
></H2
><DIV
CLASS="SECT2"
><H3
CLASS="SECT2"
><A
NAME="VC-PROJECTS"
>Support for Visual C++ projects</A
></H3
><P
>          Unfortunately Winemaker does not support the Visual C++ project 
          files, ...yet. Supporting Visual C++ project files (the 
          <TT
CLASS="FILENAME"
>.dsp</TT
> and some <TT
CLASS="FILENAME"
>.mak</TT
> files 
          for older versions of Visual C++) is definitely on 
          the list of important Winemaker improvements as it will allow it to 
          properly detect the defines to be used, any custom include path, the 
          list of libraries to link with, and exactly which source files to use
          to build a specific target. All things that the current version of 
          Winemaker has to guess or that you have to tell it as will become 
          clear in the next section.
        </P
><P
>          When the time comes Winemaker, and its associated build system, will 
          need some extensions to support:
        </P
><P
></P
><UL
><LI
><P
>              per file defines and include paths. Visual C++ projects allow 
              the user to specify compiler options for each individual file 
              being compiled. But this is probably not very frequent so it 
              might not be that important.
            </P
></LI
><LI
><P
>              multiple configurations. Visual C++ projects usually have at 
              least a 'Debug' and a 'Release' configuration which are compiled 
              with different compiler options. How exactly we deal with these 
              configurations remains to be determined.
            </P
></LI
></UL
></DIV
><DIV
CLASS="SECT2"
><HR><H3
CLASS="SECT2"
><A
NAME="SOURCE-ANALYSIS"
>Winemaker's source analysis</A
></H3
><P
>          Winemaker can do its work even without a Windows makefile or a 
          Visual Studio project to start from (it would not know what to do 
          with a windows makefile anyway). This involves doing many educated 
          guesses which may be wrong. But by and large it works. The purpose 
          of this section is to describe in more details how winemaker 
          proceeds so that you can better understand why it gets things 
          wrong and how to fix it/avoid it.
        </P
><P
>          At the core winemaker does a recursive traversal of 
          your source tree looking for targets (things to build) and source 
          files. Let's start with the targets.
        </P
><P
>          First are executables and DLLs. Each time it finds one of these in 
          a directory, winemaker puts it in the list of things to build and 
          will later generate a <TT
CLASS="FILENAME"
>Makefile</TT
> file in this 
          directory. Note that Winemaker also knows about the commonly used 
          <TT
CLASS="FILENAME"
>Release</TT
> and <TT
CLASS="FILENAME"
>Debug</TT
> 
          directories, so it will attribute the executables and libraries 
          found in these to their parent directory. When it finds an 
          executable or a DLL winemaker is happy because these give it more 
          information than the other cases described below.
        </P
><P
>          If it does not find any executable or DLL winemaker will look for 
          files with a <TT
CLASS="FILENAME"
>.mak</TT
> extension. If they are not 
          disguised Visual C++ projects (and currently even if they are), 
          winemaker will assume that a target by that name should be built 
          in this directory. But it will not know whether this target is an 
          executable or a library. So it will assume it is of the default 
          type, i.e. a graphical application, which you can override by using 
          the <CODE
CLASS="OPTION"
>--cuiexe</CODE
> and <CODE
CLASS="OPTION"
>--dll</CODE
> options.
        </P
><P
>          Finally winemaker will check to see if there is a file called 
          <TT
CLASS="FILENAME"
>makefile</TT
>. If there is, then it will assume 
          that there is exactly one target to build for this directory. But 
          it will not know the name or type of this target. For the type it 
          will do as in the above case. And for the name it will use the 
          directory's name. Actually, if the directory starts with 
          <TT
CLASS="FILENAME"
>src</TT
> winemaker will try to make use of the name 
          of the parent directory instead.
        </P
><P
>          Once the target list for a directory has been established, 
          winemaker will check whether it contains a mix of executables and 
          libraries. If it is so, then winemaker will make it so that each 
          executable is linked with all the libraries of that directory.
        </P
><P
>          If the previous two steps don't produce the expected results (or 
          you think they will not) then you should put winemaker in 
          interactive mode (see <A
HREF="#INTERACTIVE"
><I
>The interactive mode</I
></A
>). This will allow you to specify the 
          target list (and more) for each directory.
        </P
><P
>          In each directory winemaker also looks for source files: C, C++ 
          or resource files. If it also found targets to build in this 
          directory it will then try to assign each source file to one of 
          these targets based on their names. Source files that do not seem 
          to match any specific target are put in a global list for this 
          directory, see the <TT
CLASS="LITERAL"
>EXTRA_xxx</TT
> variables in the 
          <TT
CLASS="FILENAME"
>Makefile</TT
>, and linked with each of the 
          targets. The assumption here is that these source files contain 
          common code which is shared by all the targets.
          If no targets were found in the directory where these files are 
          located, then they are assigned to the parent's directory. So if a 
          target is found in the parent directory it will also 'inherit' the 
          source files found in its subdirectories.
        </P
><P
>          Finally winemaker also looks for more exotic files like 
          <TT
CLASS="FILENAME"
>.h</TT
> headers, <TT
CLASS="FILENAME"
>.inl</TT
> files 
          containing inline functions and a few others. These are not put in 
          the regular source file lists since they are not compiled directly. 
          But winemaker will still remember them so that they are processed 
          when the time comes to fix the source files.
        </P
><P
>          Fixing the source files is done as soon as winemaker has finished 
          its recursive directory traversal. The two main tasks in this step 
          are fixing the CRLF issues and verifying the case of the include 
          statements.
        </P
><P
>          Winemaker makes a backup of each source file (in such a way that 
          symbolic links are preserved), then reads it fixing the CRLF 
          issues and the other issues as it goes. Once it has finished 
          working on a file it checks whether it has done any non 
          CRLF-related modification and deletes the backup file if it did 
          not (or if you used <CODE
CLASS="OPTION"
>--nobackup</CODE
>).
        </P
><P
>          Checking the case of the include statements (of any form, 
          including files referenced by resource files), is done in the 
          context of that source file's project. This way winemaker can use 
          the proper include path when looking for the file that is included. 
          If winemaker fails to find a file in any of the directories of the 
          include path, it will rename it to lowercase on the basis that it 
          is most likely a system header and that all system headers names 
          are lowercase (this can be overridden by using 
          <CODE
CLASS="OPTION"
>--nolower-include</CODE
>).
        </P
><P
>          Finally winemaker generates the <TT
CLASS="FILENAME"
>Makefile</TT
> 
          files. From the above description 
          you can guess at the items that winemaker may get wrong in 
          this phase: macro definitions, include path, DLL path, DLLs to
          import, library path, libraries to link with. You can deal with
          these issues by using winemaker's <CODE
CLASS="OPTION"
>-D</CODE
>, <CODE
CLASS="OPTION"
>-P</CODE
>,
          <CODE
CLASS="OPTION"
>-i</CODE
>, <CODE
CLASS="OPTION"
>-I</CODE
>, <CODE
CLASS="OPTION"
>-L</CODE
> and <CODE
CLASS="OPTION"
>-l</CODE
>
          options if they are
          homogeneous enough between all your targets. Otherwise you may 
          want to use winemaker's <A
HREF="#INTERACTIVE"
>interactive 
          mode</A
> so that you can specify different settings for each 
          project / target.
        </P
><P
>          For instance, one of the problems you are likely to encounter is 
          that of the <CODE
CLASS="VARNAME"
>STRICT</CODE
> macro. Some programs will 
          not compile if <CODE
CLASS="VARNAME"
>STRICT</CODE
> is not turned on, and 
          others will not compile if it is. Fortunately all the files in a 
          given source tree use the same setting so that all you have to do 
          is add <TT
CLASS="LITERAL"
>-DSTRICT</TT
> on winemaker's command line 
          or in the <TT
CLASS="FILENAME"
>Makefile</TT
> file(s).
        </P
><P
>          Finally the most likely reasons for missing or duplicate symbols 
          are:
        </P
><P
></P
><UL
><LI
><P
>              The target is not importing the right set of DLLs, or is not
              being linked with the right set of libraries. You can avoid
              this by using winemaker's <CODE
CLASS="OPTION"
>-P</CODE
>, <CODE
CLASS="OPTION"
>-i</CODE
>,
              <CODE
CLASS="OPTION"
>-L</CODE
> and <CODE
CLASS="OPTION"
>-l</CODE
> options or adding these
              DLLs and libraries to the <TT
CLASS="FILENAME"
>Makefile</TT
> file.
            </P
></LI
><LI
><P
>              Maybe you have multiple targets in a single directory and 
              winemaker guessed wrong when trying to match the source files 
              with the targets. The only way to fix this kind of problem is 
              to edit the <TT
CLASS="FILENAME"
>Makefile</TT
> file manually.
            </P
></LI
><LI
><P
>              Winemaker assumes you have organized your source files 
              hierarchically. If a target uses source files that are in a 
              sibling directory, e.g. if you link with 
              <TT
CLASS="FILENAME"
>../hello/world.o</TT
> then you will get missing 
              symbols. Again the only solution is to manually edit the 
              <TT
CLASS="FILENAME"
>Makefile</TT
> file.
            </P
></LI
></UL
></DIV
><DIV
CLASS="SECT2"
><HR><H3
CLASS="SECT2"
><A
NAME="INTERACTIVE"
>The interactive mode</A
></H3
><P
>          what is it, 
          when to use it,
          how to use it
        </P
></DIV
><DIV
CLASS="SECT2"
><HR><H3
CLASS="SECT2"
><A
NAME="MAKEFILE"
>The Makefile files</A
></H3
><P
>          The <TT
CLASS="FILENAME"
>Makefile</TT
> is your makefile.
          So this is the file to modify if you want to customize things. 
          Here's a detailed description of its content:
        </P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>### Generic autoconf variables

TOPSRCDIR             = @top_srcdir@
TOPOBJDIR             = .
SRCDIR                = @srcdir@
VPATH                 = @srcdir@
        </PRE
></TD
></TR
></TABLE
><P
>          The above is part of the standard autoconf boiler-plate. These 
          variables make it possible to have per-architecture directories for 
          compiled files and other similar goodies (But note that this kind 
          of functionality has not been tested with winemaker generated 
          <TT
CLASS="FILENAME"
>Makefile</TT
> files yet).
        </P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>SUBDIRS               =
DLLS                  =
EXES                  = hello.exe
        </PRE
></TD
></TR
></TABLE
><P
>          This is where the targets for this directory are listed. The names 
          are pretty self-explanatory. <CODE
CLASS="VARNAME"
>SUBDIRS</CODE
> is usually 
          only present in the top-level makefile. For libraries and
          executables, specify the full name, including the '.dll' or '.exe'
          extension. Note that these names must be in all lowercase.
        </P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>### Global settings

DEFINES               = -DSTRICT
INCLUDE_PATH          =
DLL_PATH              =
LIBRARY_PATH          =
LIBRARIES             =
        </PRE
></TD
></TR
></TABLE
><P
>          This section contains the global compilation settings: they apply
          to all the targets in this makefile. The <CODE
CLASS="VARNAME"
>LIBRARIES</CODE
>
          variable allows you to specify additional Unix libraries to link
          with. Note that you would normally not specify Winelib libraries
          there. To link with a Winelib library, one uses the <CODE
CLASS="VARNAME"
>DLLS</CODE
>
          variables of the Makefile. The exception is for C++ libraries where
          you currently don't have  a choice but to link with them in the
          Unix sense. One library you are likely to find here is 
          <TT
CLASS="LITERAL"
>mfc</TT
> (note, the '-l' is omitted).
        </P
><P
>          The other variable 
          names should be self-explanatory. You can also use three additional 
          variables that are usually not present in the file: 
          <CODE
CLASS="VARNAME"
>CEXTRA</CODE
>, <CODE
CLASS="VARNAME"
>CXXEXTRA</CODE
> and 
          <CODE
CLASS="VARNAME"
>WRCEXTRA</CODE
> which allow you to specify additional 
          flags for, respectively, the C compiler, the C++ compiler and the 
          resource compiler. Finally note that all these variable contain 
          the option's name.
        </P
><P
>          Then come one section per target, each describing the various 
          components that target is made of.
        </P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>### hello.exe sources and settings

hello_exe_C_SRCS          = hello.c
hello_exe_CXX_SRCS        =
hello_exe_RC_SRCS         =
hello_exe_SPEC_SRCS       =
        </PRE
></TD
></TR
></TABLE
><P
>          Each section will start with a comment indicating the name of the 
          target. Then come a series of variables prefixed with the name of 
          that target. Note that the name of the prefix may be slightly 
          different from that of the target because of restrictions on the 
          variable names.
        </P
><P
>          The above variables list the sources that are used togenerate the 
          target. Note that there should only be one resource file in 
          <CODE
CLASS="VARNAME"
>RC_SRCS</CODE
>, and that <CODE
CLASS="VARNAME"
>SPEC_SRCS</CODE
> 
          will usually be empty for executables, and will contain a single
          spec file for libraries.
        </P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>hello_exe_DLL_PATH        =
hello_exe_DLLS            =
hello_exe_LIBRARY_PATH    =
hello_exe_LIBRARIES       =
hello_exe_DEPENDS         =
        </PRE
></TD
></TR
></TABLE
><P
>          The above variables specify how to link the target. Note that they 
          add to the global settings we saw at the beginning of this file.
        </P
><P
>          The <CODE
CLASS="VARNAME"
>DLLS</CODE
> field is where you would enumerate the list of
          DLLs that executable imports. It should contain the full DLL name
          including the '.dll' extension, but not the '-l' option.
        </P
><P
>          <CODE
CLASS="VARNAME"
>DEPENDS</CODE
>, when present, specifies a list of other 
          targets that this target depends on. Winemaker will automatically 
          fill this field when an executable and a library are built in the
          same directory.
        </P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>hello_exe_OBJS        = $(hello_exe_C_SRCS:.c=.o) \
                        $(hello_exe_CXX_SRCS:.cpp=.o) \
                        $(EXTRA_OBJS)
        </PRE
></TD
></TR
></TABLE
><P
>          The above just builds a list of all the object files that 
          correspond to this target. This list is later used for the link 
          command.
        </P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>### Global source lists

C_SRCS                = $(hello_exe_C_SRCS)
CXX_SRCS              = $(hello_exe_CXX_SRCS)
RC_SRCS               = $(hello_exe_RC_SRCS)
SPEC_SRCS             = $(hello_exe_SPEC_SRCS)
        </PRE
></TD
></TR
></TABLE
><P
>          This section builds 'summary' lists of source files. These lists are 
          used by the <TT
CLASS="FILENAME"
>Make.rules</TT
> file.
        </P
><DIV
CLASS="NOTE"
><P
></P
><TABLE
CLASS="NOTE"
WIDTH="100%"
BORDER="0"
><TR
><TD
WIDTH="25"
ALIGN="CENTER"
VALIGN="TOP"
><IMG
SRC="./stylesheet-images/note.gif"
HSPACE="5"
ALT="Note"></TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><P
>          FIXME:The following is not up-to-date.
        </P
></TD
></TR
></TABLE
></DIV
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>### Generic autoconf targets

all: $(DLLS:%=%.so) $(EXES:%=%.so)

@MAKE_RULES@

install::
        for i in $(EXES); do $(INSTALL_PROGRAM) $$i $(bindir); done
        for i in $(EXES:%=%.so) $(DLLS); do $(INSTALL_LIBRARY) $$i $(libdir); done

uninstall::
        for i in $(EXES); do $(RM) $(bindir)/$$i;done
        for i in $(EXES:%=%.so) $(DLLS); do $(RM) $(libdir)/$$i;done
        </PRE
></TD
></TR
></TABLE
><P
>          The above first defines the default target for this makefile. Here 
          it consists in trying to build all the targets. Then it includes 
          the <TT
CLASS="FILENAME"
>Make.rules</TT
> file which contains the build 
          logic, and provides a few more standard targets to install / 
          uninstall the targets. 
        </P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>### Target specific build rules

$(hello_SPEC_SRCS:.spec=.tmp.o): $(hello_OBJS)
        $(LDCOMBINE) $(hello_OBJS) -o $@
        -$(STRIP) $(STRIPFLAGS) $@

$(hello_SPEC_SRCS:.spec=.spec.c): $(hello_SPEC_SRCS:.spec) $(hello_SPEC_SRCS:.spec=.tmp.o) $(hello_RC_SRCS:.rc=.res)
        $(WINEBUILD) -fPIC $(hello_LIBRARY_PATH) $(WINE_LIBRARY_PATH) -sym $(hello_SPEC_SRCS:.spec=.tmp.o) -o $@ -spec $(hello_SPEC_SRCS)

hello.so: $(hello_SPEC_SRCS:.spec=.spec.o) $(hello_OBJS) $(hello_DEP
ENDS) 
        $(LDSHARED) $(LDDLLFLAGS) -o $@ $(hello_OBJS) $(hello_SPEC_SRCS:.spec=.spec.o) $(hello_LIBRARY_PATH) $(hello_LIBRARIES:%=-l%) $(DLL_LINK) $(LIBS)
        test -f hello || $(LN_S) $(WINE) hello
        </PRE
></TD
></TR
></TABLE
><P
>          Then come additional directives to link the executables and 
          libraries. These are pretty much standard and you should not need 
          to modify them.
        </P
></DIV
></DIV
><DIV
CLASS="SECT1"
><HR><H2
CLASS="SECT1"
><A
NAME="WRC"
>Compiling resource files: WRC</A
></H2
><P
>        To compile resources you should use the Wine Resource Compiler, 
        wrc for short, which produces a binary <TT
CLASS="FILENAME"
>.res</TT
> 
        file. This resource file is then used by winebuild when compiling 
        the spec file (see <A
HREF="#SPEC-FILE"
><I
>The Spec file</I
></A
>).
      </P
><P
>        Again the makefiles generated by winemaker take care of this for you. 
        But if you were to write your own makefile you would put something 
        like the following:
      </P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>WRC=$(WINE_DIR)/tools/wrc/wrc

WINELIB_FLAGS = -I$(WINE_DIR)/include -DWINELIB -D_REENTRANT
WRCFLAGS      = -r -L

.SUFFIXES: .rc .res

.rc.res:
	$(WRC) $(WRCFLAGS) $(WINELIB_FLAGS) -o $@ $&#60;
      </PRE
></TD
></TR
></TABLE
><P
>        There are two issues you are likely to encounter with resource files.
      </P
><P
>        The first problem is with the C library headers. WRC does not know 
        where these headers are located. So if an RC file, of a file it 
        includes, references such a header you will get a 'file not found' 
        error from wrc. Here are a few ways to deal with this:
      </P
><P
></P
><UL
><LI
><P
>            The solution traditionally used by the Winelib headers is to 
            enclose the offending include statement in an 
            <TT
CLASS="LITERAL"
>#ifndef RC_INVOKED</TT
> statement where 
            <CODE
CLASS="VARNAME"
>RC_INVOKED</CODE
> is a macro name which is 
            automatically defined by wrc.
          </P
></LI
><LI
><P
>            Alternately you can add one or more <CODE
CLASS="OPTION"
>-I</CODE
> directive 
            to your wrc command so that it finds you system files. For 
            instance you may add <TT
CLASS="LITERAL"
>-I/usr/include 
            -I/usr/lib/gcc-lib/i386-linux/2.95.2/include</TT
> to cater 
            to both C and C++ headers. But this supposes that you know where 
            these header files reside which decreases the portability of your 
            makefiles to other platforms (unless you automatically detect all 
            the necessary directories in the autoconf script).
          </P
><P
>            Or you could use the C/C++ compiler to perform the preprocessing. 
            To do so, simply modify your makefile as follows:
          </P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="90%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>.rc.res:
	$(CC) $(CC_OPTS) -DRC_INVOKED -E -x c $&#60; | $(WRC) -N $(WRCFLAGS) $(WINELIB_FLAGS) -o $@

          </PRE
></TD
></TR
></TABLE
></LI
></UL
><P
>        The second problem is that the headers may contain constructs that 
        WRC fails to understand. A typical example is a function which return 
        a 'const' type. WRC expects a function to be two identifiers followed 
        by an opening parenthesis. With the const this is three identifiers 
        followed by a parenthesis and thus WRC is confused (note: WRC should 
        in fact ignore all this like the windows resource compiler does). 
        The current work-around is to enclose offending statement(s) in an 
        <TT
CLASS="LITERAL"
>#ifndef RC_INVOKED</TT
>.
      </P
><P
>        Using GIF files in resources is problematic. For best results,
        convert them to BMP and change your <TT
CLASS="FILENAME"
>.res</TT
>
        file.
      </P
><P
>        If you use common controls/dialogs in your resource files, you
        will need to add <TT
CLASS="FUNCTION"
>#include &#60;commctrl.h&#62;</TT
>
        after the <TT
CLASS="FUNCTION"
>#include &#60;windows.h&#62;</TT
> line,
        so that <B
CLASS="COMMAND"
>wrc</B
> knows the values of control
        specific flags.
      </P
></DIV
><DIV
CLASS="SECT1"
><HR><H2
CLASS="SECT1"
><A
NAME="WMC"
>Compiling message files: WMC</A
></H2
><P
>        how does one use it???
      </P
></DIV
><DIV
CLASS="SECT1"
><HR><H2
CLASS="SECT1"
><A
NAME="SPEC-FILE"
>The Spec file</A
></H2
><DIV
CLASS="SECT2"
><H3
CLASS="SECT2"
><A
NAME="SPEC-INTRO"
>Introduction</A
></H3
><P
>          In Windows the program's life starts either when its 
          <TT
CLASS="FUNCTION"
>main</TT
> is called,  for console applications, or 
          when its <TT
CLASS="FUNCTION"
>WinMain</TT
> is called, for windows 
          applications in the 'windows' subsystem. On Unix it is always 
          <TT
CLASS="FUNCTION"
>main</TT
> that is called. Furthermore in Winelib it 
          has some special tasks to accomplish, such as initializing Winelib, 
          that a normal <TT
CLASS="FUNCTION"
>main</TT
> does not have to do.
        </P
><P
>          Furthermore windows applications and libraries contain some 
          information which are necessary to make APIs such as 
          <TT
CLASS="FUNCTION"
>GetProcAddress</TT
> work. So it is necessary to 
          duplicate these data structures in the Unix world to make these 
          same APIs work with Winelib applications and libraries.
        </P
><P
>          The spec file is there to solve the semantic gap described above. 
          It provides the <TT
CLASS="FUNCTION"
>main</TT
> function that initializes 
          Winelib and calls the module's <TT
CLASS="FUNCTION"
>WinMain</TT
> / 
          <TT
CLASS="FUNCTION"
>DllMain</TT
>, and it contains information about 
          each API exported from a Dll so that the appropriate tables can be 
          generated.
        </P
><P
>          A typical spec file will look something like this:
        </P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="SCREEN"
>init    WinMain
rsrc    resource.res
        </PRE
></TD
></TR
></TABLE
><P
>          And here are the entries you will probably want to change: 
        </P
><P
></P
><DIV
CLASS="VARIABLELIST"
><DL
><DT
>init</DT
><DD
><P
>                <TT
CLASS="LITERAL"
>init</TT
> defines what is the entry point of 
                that module. For a library this is customarily set to 
                <TT
CLASS="LITERAL"
>DllMain</TT
>, for a console application this 
                is <TT
CLASS="LITERAL"
>main</TT
> and for a graphical application 
                this is <TT
CLASS="LITERAL"
>WinMain</TT
>.
              </P
></DD
><DT
>rsrc</DT
><DD
><P
>                This item specifies the name of the compiled resource file 
                to link with your module. If your resource file is called 
                <TT
CLASS="FILENAME"
>hello.rc</TT
> then the wrc compilation step
                (see <A
HREF="#WRC"
><I
>Compiling resource files: WRC</I
></A
>) will generate 
                a file called <TT
CLASS="FILENAME"
>hello.res</TT
>. This is the 
                name you must provide here. Note that because of this you 
                cannot compile the spec file before you have compiled the 
                resource file. So you should put a rule like the following 
                in your makefile:
              </P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="90%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>hello.spec.c: hello.res
              </PRE
></TD
></TR
></TABLE
><P
>                If your project does not have a resource file then you must 
                omit this entry altogether.
              </P
></DD
><DT
>@</DT
><DD
><DIV
CLASS="NOTE"
><P
></P
><TABLE
CLASS="NOTE"
WIDTH="90%"
BORDER="0"
><TR
><TD
WIDTH="25"
ALIGN="CENTER"
VALIGN="TOP"
><IMG
SRC="./stylesheet-images/note.gif"
HSPACE="5"
ALT="Note"></TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><P
>                FIXME: You must now export functions from DLLs.
              </P
></TD
></TR
></TABLE
></DIV
><P
>                This entry is not shown above because it is not always 
                necessary. In fact it is only necessary to export functions 
                when you plan to dynamically load the library with 
                <TT
CLASS="FUNCTION"
>LoadLibrary</TT
> and then do a 
                <TT
CLASS="FUNCTION"
>GetProcAddress</TT
> on these functions. 
                This is not necessary if you just plan on linking with the 
                library and calling the functions normally. For more details 
                about this see: <A
HREF="#SPEC-REFERENCE"
><I
>More details</I
></A
>.
              </P
></DD
></DL
></DIV
></DIV
><DIV
CLASS="SECT2"
><HR><H3
CLASS="SECT2"
><A
NAME="SPEC-COMPILING"
>Compiling it</A
></H3
><DIV
CLASS="NOTE"
><P
></P
><TABLE
CLASS="NOTE"
WIDTH="100%"
BORDER="0"
><TR
><TD
WIDTH="25"
ALIGN="CENTER"
VALIGN="TOP"
><IMG
SRC="./stylesheet-images/note.gif"
HSPACE="5"
ALT="Note"></TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><P
>            FIXME: This section is very outdated and does not correctly
            describe the current use of winebuild and spec files. In
            particular, with recent versions of winebuild most of the
            information that used to be in the spec files is now specified on
            the command line.
          </P
></TD
></TR
></TABLE
></DIV
><P
>            Compiling a spec file is a two step process. It is first 
            converted into a C file by winebuild, and then compiled into an 
            object file using your regular C compiler. This is all taken 
            care of by the winemaker generated makefiles of course. But 
            here's what it would like if you had to do it by hand:
          </P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="SCREEN"
>WINEBUILD=$(WINE_DIR)/tools/winebuild

.SUFFIXES: .spec .spec.c .spec.o

.spec.spec.c:
	$(WINEBUILD) -fPIC -o $@ -spec $&#60;

.spec.c.spec.o:
	$(CC) -c -o $*.spec.o $&#60;
          </PRE
></TD
></TR
></TABLE
><P
>            Nothing really complex there. Just don't forget the 
            <TT
CLASS="LITERAL"
>.SUFFIXES</TT
> statement, and beware of the tab if 
            you copy this straight to your Makefile.
          </P
></DIV
><DIV
CLASS="SECT2"
><HR><H3
CLASS="SECT2"
><A
NAME="SPEC-REFERENCE"
>More details</A
></H3
><P
>          Here is a more detailed description of the spec file's format.
        </P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
># comment text
        </PRE
></TD
></TR
></TABLE
><P
>          Anything after a '#' will be ignored as comments.
        </P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>init    FUNCTION
        </PRE
></TD
></TR
></TABLE
><P
>          This field is optional and specific to Win32 modules. It 
          specifies a function which will be called when the DLL is loaded 
          or the executable started.
        </P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>rsrc    RES_FILE
        </PRE
></TD
></TR
></TABLE
><P
>          This field is optional. If present it specifies the name of the 
          .res file containing the compiled resources. See <A
HREF="#WRC"
><I
>Compiling resource files: WRC</I
></A
> for details on compiling a 
          resource file.
        </P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>ORDINAL VARTYPE EXPORTNAME (DATA [DATA [DATA [...]]])
2 byte Variable(-1 0xff 0 0)
        </PRE
></TD
></TR
></TABLE
><P
>          This field can be present zero or more times.
          Each instance defines data storage at the ordinal specified. You 
          may store items as bytes, 16-bit words, or 32-bit words.
          <TT
CLASS="LITERAL"
>ORDINAL</TT
> is replaced by the ordinal number 
          corresponding to the variable. <TT
CLASS="LITERAL"
>VARTYPE</TT
> should 
          be <TT
CLASS="LITERAL"
>byte</TT
>, <TT
CLASS="LITERAL"
>word</TT
> or 
          <TT
CLASS="LITERAL"
>long</TT
> for 8, 16, or 32 bits respectively. 
          <TT
CLASS="LITERAL"
>EXPORTNAME</TT
> will be the name available for
          dynamic linking. <TT
CLASS="LITERAL"
>DATA</TT
> can be a decimal number 
          or a hex number preceded by "0x". The example defines the 
          variable <TT
CLASS="LITERAL"
>Variable</TT
> at ordinal 2 and containing 
          4 bytes.
        </P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>ORDINAL equate EXPORTNAME DATA
        </PRE
></TD
></TR
></TABLE
><P
>          This field can be present zero or more times.
          Each instance defines an ordinal as an absolute value.
          <TT
CLASS="LITERAL"
>ORDINAL</TT
> is replaced by the ordinal number 
          corresponding to the variable. <TT
CLASS="LITERAL"
>EXPORTNAME</TT
> will 
          be the name available for dynamic linking. 
          <TT
CLASS="LITERAL"
>DATA</TT
> can be a decimal number or a hex number 
          preceded by "0x".
        </P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>ORDINAL FUNCTYPE EXPORTNAME([ARGTYPE [ARGTYPE [...]]]) HANDLERNAME
100 pascal CreateWindow(ptr ptr long s_word s_word s_word s_word
                        word word word ptr)
           WIN_CreateWindow
101 pascal GetFocus() WIN_GetFocus()
        </PRE
></TD
></TR
></TABLE
><P
>          This field can be present zero or more times.
          Each instance defines a function entry point. The prototype 
          defined by <TT
CLASS="LITERAL"
>EXPORTNAME ([ARGTYPE [ARGTYPE [...]]])</TT
> 
          specifies the name available for dynamic linking and the format 
          of the arguments. <TT
CLASS="LITERAL"
>ORDINAL</TT
> is replaced
          by the ordinal number corresponding to the function, or 
          <TT
CLASS="LITERAL"
>@</TT
> for automatic ordinal allocation (Win32 only).
        </P
><P
>          <TT
CLASS="LITERAL"
>FUNCTYPE</TT
> should be one of:
        </P
><P
></P
><DIV
CLASS="VARIABLELIST"
><DL
><DT
>pascal16</DT
><DD
><P
>                for a Win16 function returning a 16-bit value
              </P
></DD
><DT
>pascal</DT
><DD
><P
>                for a Win16 function returning a 32-bit value
              </P
></DD
><DT
>register</DT
><DD
><P
>                for a function using CPU register to pass arguments
              </P
></DD
><DT
>interrupt</DT
><DD
><P
>                for a Win16 interrupt handler routine
              </P
></DD
><DT
>stdcall</DT
><DD
><P
>                for a normal Win32 function
              </P
></DD
><DT
>cdecl</DT
><DD
><P
>                for a Win32 function using the C calling convention
              </P
></DD
><DT
>varargs</DT
><DD
><P
>                for a Win32 function taking a variable number of arguments
              </P
></DD
></DL
></DIV
><P
>          <TT
CLASS="LITERAL"
>ARGTYPE</TT
> should be one of:
        </P
><P
></P
><DIV
CLASS="VARIABLELIST"
><DL
><DT
>word</DT
><DD
><P
>                for a 16 bit word
              </P
></DD
><DT
>long</DT
><DD
><P
>                a 32 bit value
              </P
></DD
><DT
>ptr</DT
><DD
><P
>                for a linear pointer
              </P
></DD
><DT
>str</DT
><DD
><P
>                for a linear pointer to a null-terminated string
              </P
></DD
><DT
>s_word</DT
><DD
><P
>                for a 16 bit signed word
              </P
></DD
><DT
>segptr</DT
><DD
><P
>                for a segmented pointer
              </P
></DD
><DT
>segstr</DT
><DD
><P
>                for a segmented pointer to a null-terminated string
              </P
></DD
><DT
>wstr</DT
><DD
><P
>                for a linear pointer to a null-terminated wide
                (16-bit Unicode) string
              </P
></DD
></DL
></DIV
><P
>          Only <TT
CLASS="LITERAL"
>ptr</TT
>, <TT
CLASS="LITERAL"
>str</TT
>,
          <TT
CLASS="LITERAL"
>wstr</TT
> and
          <TT
CLASS="LITERAL"
>long</TT
> are valid for Win32 functions.
          <TT
CLASS="LITERAL"
>HANDLERNAME</TT
> is the name of the actual Wine 
          function that will process the request in 32-bit mode.
        </P
><P
>          Strings should almost always map to str, 
          wide strings - wstr.
          As the general rule it depends on whether the
          parameter is IN, OUT or IN/OUT.
        </P
><P
></P
><UL
><LI
><P
>              IN: str/wstr
            </P
></LI
><LI
><P
>              OUT: ptr
            </P
></LI
><LI
><P
>              IN/OUT: str/wstr
            </P
></LI
></UL
><P
>          It is for debug messages. If the parameter is OUT
          it might not be initialized and thus it should not
          be printed as a string.
        </P
><P
>          The two examples define an entry point for the 
          <TT
CLASS="FUNCTION"
>CreateWindow</TT
> and <TT
CLASS="FUNCTION"
>GetFocus</TT
> 
          calls respectively. The ordinals used are just examples.
        </P
><P
>          To declare a function using a variable number of arguments in 
          Win16, specify the function as taking no arguments. The arguments 
          are then available with CURRENT_STACK16-&#62;args. In Win32, specify 
          the function as <TT
CLASS="LITERAL"
>varargs</TT
> and declare it with a 
          '...' parameter in the C file.  See the wsprintf* functions in 
          <TT
CLASS="FILENAME"
>user.spec</TT
> and 
          <TT
CLASS="FILENAME"
>user32.spec</TT
> for an example.
        </P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>ORDINAL stub EXPORTNAME
        </PRE
></TD
></TR
></TABLE
><P
>          This field can be present zero or more times.
          Each instance defines a stub function. It makes the ordinal 
          available for dynamic linking, but will terminate execution with 
          an error message if the function is ever called.
        </P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>ORDINAL extern EXPORTNAME SYMBOLNAME
        </PRE
></TD
></TR
></TABLE
><P
>          This field can be present zero or more times.
          Each instance defines an entry that simply maps to a Wine symbol
          (variable or function); <TT
CLASS="LITERAL"
>EXPORTNAME</TT
> will point 
          to the symbol <TT
CLASS="LITERAL"
>SYMBOLNAME</TT
> that must be defined 
          in C code. This type only works with Win32.
        </P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>ORDINAL forward EXPORTNAME SYMBOLNAME
        </PRE
></TD
></TR
></TABLE
><P
>          This field can be present zero or more times.
          Each instance defines an entry that is forwarded to another entry
          point (kind of a symbolic link). <TT
CLASS="LITERAL"
>EXPORTNAME</TT
>
          will forward to the entry point <TT
CLASS="LITERAL"
>SYMBOLNAME</TT
> 
          that must be of the form <TT
CLASS="LITERAL"
>DLL.Function</TT
>. This 
          type only works with Win32.
        </P
></DIV
></DIV
><DIV
CLASS="SECT1"
><HR><H2
CLASS="SECT1"
><A
NAME="LINKING"
>Linking it all together</A
></H2
><DIV
CLASS="NOTE"
><P
></P
><TABLE
CLASS="NOTE"
WIDTH="100%"
BORDER="0"
><TR
><TD
WIDTH="25"
ALIGN="CENTER"
VALIGN="TOP"
><IMG
SRC="./stylesheet-images/note.gif"
HSPACE="5"
ALT="Note"></TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><P
>        FIXME:The following is not up-to-date.
      </P
></TD
></TR
></TABLE
></DIV
><P
>        To link an executable you need to link together: your object files, 
        the spec file, any Windows libraries that your application depends
        on, gdi32 for instance, and any additional library that you use. All 
        the libraries you link with should be available as '.so' libraries. 
        If one of them is available only in '.dll' form then consult 
        <A
HREF="#BINDLLS"
><I
>Building WineLib DLLs</I
></A
>.
      </P
><P
>        It is also when attempting to link your executable that you will 
        discover whether you have missing symbols or not in your custom 
        libraries. On Windows when you build a library, the linker will 
        immediately tell you if a symbol it is supposed to export is 
        undefined. In Unix, and in Winelib, this is not the case. The symbol 
        will silently be marked as undefined and it is only when you try to 
        produce an executable that the linker will verify all the symbols are 
        accounted for.
      </P
><P
>        So before declaring victory when first converting a library to 
        Winelib, you should first try to link it to an executable (but you 
        would have done that to test it anyway, right?). At this point you 
        may discover some undefined symbols that you thought were implemented 
        by the library. Then, you to the library sources and fix it. But you 
        may also discover that the missing symbols are defined in, say, 
        gdi32. This is because you did not link the said library with gdi32. 
        One way to fix it is to link this executable, and any other that also 
        uses your library, with gdi32. But it is better to go back to your 
        library's makefile and explicitly link it with gdi32.
      </P
><P
>        As you will quickly notice, this has unfortunately not been 
        (completely) done for Winelib's own libraries. So if an application 
        must link with ole32, you will also need to link with advapi32, 
        rpcrt4 and others even if you don't use them directly. This can be 
        annoying and hopefully will be fixed soon (feel free to submit a 
        patch).
      </P
></DIV
></DIV
><DIV
CLASS="CHAPTER"
><HR><H1
><A
NAME="MFC"
></A
>Dealing with the MFC</H1
><DIV
CLASS="SECT1"
><H2
CLASS="SECT1"
><A
NAME="MFC-INTRODUCTION"
>Introduction</A
></H2
><P
>        To use the MFC in a Winelib application you will first have to
        recompile the MFC with Winelib. In theory it should be possible to
        write a wrapper for the Windows MFC as described in
        <A
HREF="#BINDLLS"
><I
>Building WineLib DLLs</I
></A
>. But in practice
        it does not seem to be a realistic approach for the MFC:
      </P
><P
></P
><UL
><LI
><P
>            the huge number of APIs makes writing the wrapper a big task in
            itself.
          </P
></LI
><LI
><P
>            furthermore the MFC contain a huge number of APIs which are tricky
            to deal with when making a wrapper.
          </P
></LI
><LI
><P
>            even once you have written the wrapper you will need to modify
            the MFC headers so that the compiler does not choke on them.
          </P
></LI
><LI
><P
>            a big part of the MFC code is actually in your application in
            the form of macros. This means even more of the MFC headers have
            to actually work to in order for you to be able to compile an
            MFC based application.
          </P
></LI
></UL
><P
>        This is why this guide includes a section dedicated to helping you
        compile the MFC with Winelib.
      </P
></DIV
><DIV
CLASS="SECT1"
><HR><H2
CLASS="SECT1"
><A
NAME="MFC-LEGAL-ISSUES"
>Legal issues</A
></H2
><P
>        The purpose of this section is to make you aware of potential legal
        problems. Be sure to read your licenses and to consult your lawyers.
        In any case you should not consider the remainder of this section to
        be authoritative since it has not been written by a lawyer.
      </P
><P
>        During the compilation of your program, you will be combining code
        from several sources: your code, Winelib code, Microsoft MFC code,
        and possibly code from other vendor sources. As a result, you must
        ensure that the licenses of all code sources are obeyed. What you are
        allowed and not allowed to do can vary depending on how you combine
        the code and if you will be distributing it. For example, if you
        are releasing your code under the GPL or LGPL, you cannot use MFC
        because these licenses do not allow covered code to depend on
        libraries with non-compatible licenses.
        There is a workaround - in the license for your
        code you can make an exception for the MFC library.
        For details see
        <A
HREF="http://www.gnu.org/licenses/gpl-faq.html"
TARGET="_top"
>The GNU GPL FAQ</A
>.
      </P
><P
>        Wine/Winelib is distributed under the GNU Lesser General Public
        License. See the license for restrictions on the modification and
        distribution of Wine/Winelib code. In general it is possible to
        satisfy these restrictions in any type of application.
        On the other hand, MFC
        is distributed under a very restrictive license and the restrictions
        vary from version to version and between service packs. There are
        basically three aspects you must be aware of when using the MFC.
      </P
><P
>        First you must legally get MFC source code on your computer. The MFC
        source code comes as a part of Visual Studio. The license for
        Visual Studio implies it is a single product that cannot
        be broken up into its components. So the cleanest way to get MFC on
        your system is to buy Visual Studio and install it on a dual boot
        Linux box.
      </P
><P
>        Then you must check that you are allowed to recompile MFC on a
        non-Microsoft operating system! This varies with the version of MFC.
        The MFC license from Visual Studio 6.0 reads in part:
      </P
><A
NAME="AEN601"
></A
><BLOCKQUOTE
CLASS="BLOCKQUOTE"
><P
>          1.1 General License Grant. Microsoft grants to you as an
          individual, a personal, nonexclusive license to make and use
          copies of the SOFTWARE PRODUCT for the sole purposes of designing,
          developing, and testing your software product(s) that are designed
          to operate in conjunction with any Microsoft operating system
          product. [Other unrelated stuff deleted.]
        </P
></BLOCKQUOTE
><P
>        So it appears you cannot even compile MFC for Winelib using this
        license. Fortunately the Visual Studio 6.0 service pack 3 license
        reads (the Visual Studio 5.0 license is similar):
      </P
><A
NAME="AEN604"
></A
><BLOCKQUOTE
CLASS="BLOCKQUOTE"
><P
>          1.1 General License Grant. Microsoft grants to you as an
          individual, a personal, nonexclusive license to make and use
          copies of the SOFTWARE PRODUCT for the purpose of designing,
          developing, and testing your software product(s). [Other unrelated
          stuff deleted]
        </P
></BLOCKQUOTE
><P
>        So under this license it appears you can compile MFC for Winelib.
      </P
><P
>        Finally you must check whether you have the right to distribute an
        MFC library. Check the relevant section of the license on
        <SPAN
CLASS="QUOTE"
>"redistributables and your redistribution rights"</SPAN
>. The
        license seems to specify that you only have the right to distribute
        binaries of the MFC library if it has no debug information and if
        you distribute it with an application that provides significant
        added functionality to the MFC library.
        
      </P
></DIV
><DIV
CLASS="SECT1"
><HR><H2
CLASS="SECT1"
><A
NAME="MFC-COMPILING"
>Compiling the MFC</A
></H2
><P
>        Here is a set of recommendations for getting the MFC compiled with
        WineLib:
      </P
><P
>        We recommend running winemaker in
        '<CODE
CLASS="OPTION"
>--interactive</CODE
>' mode to specify the right
        options for the MFC and the ATL part (to get the include paths
        right, to not consider the MFC MFC-based, and to get it to
        build libraries, not executables).
      </P
><P
>        Then when compiling it you will indeed need a number of
        <TT
CLASS="LITERAL"
>_AFX_NO_XXX</TT
> macros. But this is not enough
        and there are other things you will need to
        '<TT
CLASS="LITERAL"
>#ifdef</TT
>-out'.  For instance Wine's richedit
        support is not very good.  Here are the AFX options I use:
      </P
><P
>        <TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>#define _AFX_PORTABLE
#define _FORCENAMELESSUNION
#define _AFX_NO_DAO_SUPPORT
#define _AFX_NO_DHTML_SUPPORT
#define _AFX_NO_OLEDB_SUPPORT
#define _AFX_NO_RICHEDIT_SUPPORT
        </PRE
></TD
></TR
></TABLE
>
      </P
><P
>        You will also need custom ones for
        <TT
CLASS="FUNCTION"
>CMonikerFile</TT
>, <TT
CLASS="FUNCTION"
>OleDB</TT
>,
        <TT
CLASS="FUNCTION"
>HtmlView</TT
>, ...
      </P
><P
>        We recommend using Wine's msvcrt headers (<TT
CLASS="LITERAL"
>-isystem
        $(WINE_INCLUDE_ROOT)/msvcrt</TT
>), though it means you
        will have to temporarily disable winsock support
        (<TT
CLASS="LITERAL"
>#ifdef</TT
> it out in
        <TT
CLASS="FILENAME"
>windows.h</TT
>).
      </P
><P
>        You should use g++ compiler more recent than g++ 2.95. g++
        2.95 does not support unnamed structs while the more recent
        ones do, and this helps a lot. Here are the options worth
        mentioning:
        <P
></P
><UL
><LI
><P
>              <TT
CLASS="LITERAL"
>-fms-extensions</TT
> (helps get more code
              to compile)
            </P
></LI
><LI
><P
>              <TT
CLASS="LITERAL"
>-fshort-wchar -DWINE_UNICODE_NATIVE</TT
>
              (helps with Unicode support)
            </P
></LI
><LI
><P
>              <TT
CLASS="LITERAL"
>-DICOM_USE_COM_INTERFACE_ATTRIBUTE</TT
>
              (to get the COM code to work)
            </P
></LI
></UL
>
      </P
><P
>        When you first reach the link stage you will get a lot of
        undefined symbol errors. To fix these you will need to go back
        to the source and <TT
CLASS="LITERAL"
>#ifdef</TT
>-out more code
        until you reach a 'closure'. There are also some files that
        don't need to be compiled.
      </P
><P
>        Maybe we will have ready-made makefile here someday...
      </P
></DIV
></DIV
><DIV
CLASS="CHAPTER"
><HR><H1
><A
NAME="BINDLLS"
></A
>Building WineLib DLLs</H1
><DIV
CLASS="SECT1"
><H2
CLASS="SECT1"
><A
NAME="BINDLLS-INTRO"
>Introduction</A
></H2
><P
>        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:
        <P
></P
><UL
><LI
><P
>              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.
            </P
></LI
><LI
><P
>              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).
            </P
></LI
><LI
><P
>	      You have a binary only Windows application that can be extended 
	      through plugins, such as a text editor or IDE.
            </P
></LI
></UL
>
      </P
><P
>        The process for dealing with these situations is actually quite simple.
        You need to write a spec file that will describe the library's 
        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 config
        file to ensure that this new built-in DLL is called rather than any
        windows version.
      </P
><P
>        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 
        <TT
CLASS="FILENAME"
>dlls/odbc32</TT
> directory of the
        Wine source.
      </P
><P
>         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.
       </P
><P
>         Specifically, the application calls a function:
<TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>signed short WINAPI MyWinFunc (unsigned short a, void *b, void *c,
        unsigned long *d, void *e, int f, char g, unsigned char *h);</PRE
></TD
></TR
></TABLE
>
         and the linux library exports a corresponding function:
<TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>signed short MyLinuxFunc (unsigned short a, void *b, void *c,
        unsigned short *d, void *e, char g, unsigned char *h);</PRE
></TD
></TR
></TABLE
>
       </P
></DIV
><DIV
CLASS="SECT1"
><HR><H2
CLASS="SECT1"
><A
NAME="BINDLLS-SPEC"
>Writing the spec file</A
></H2
><P
>        Start by writing the spec file.  This file will describe the interface
        as if it were a DLL.  See elsewhere for the details of the format of
        a spec file (e.g. man winebuild).
      </P
><P
>        In the simple example we want a Wine built-in Dll that corresponds to
        the MyWin Dll.  The spec file is <TT
CLASS="FILENAME"
>MyWin.dll.spec</TT
> and
        looks something like this:
<TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>#
# File: MyWin.dll.spec
#
# some sort of copyright
#
# Wine spec file for the MyWin.dll built-in library (a minimal wrapper around the
# linux library libMyLinux)
#
# For further details of wine spec files see the Winelib documentation at
# www.winehq.org

2 stdcall MyWinFunc (long ptr ptr ptr ptr long long ptr) MyProxyWinFunc

# End of file</PRE
></TD
></TR
></TABLE
>
        Notice that the arguments are flagged as long even though they are
        smaller than that.  With this example we will link directly to the 
	Linux shared library whereas with the ODBC example we will load the 
	Linux shared library dynamically.
      </P
><P
>        In the case of the ODBC example you can see this in the file 
        <TT
CLASS="FILENAME"
>odbc32.spec</TT
>.
      </P
></DIV
><DIV
CLASS="SECT1"
><HR><H2
CLASS="SECT1"
><A
NAME="BINDLLS-WRAPPER"
>Writing the wrapper</A
></H2
><P
>        Firstly we will look at the simple example.  The main complication of
        this case is the slightly different argument lists.  The f parameter
        does not have to be passed to the Linux function and the d parameter
        (theoretically) has to be converted between 
	<TT
CLASS="LITERAL"
>unsigned long *i</TT
> and <TT
CLASS="LITERAL"
>unsigned short *</TT
>.  
	Doing this ensures that the "high" bits of the returned value are set 
	correctly.  Also unlike with the ODBC example we will link directly to
	the Linux Shared Library.
        <TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>/*
 * File: MyWin.c
 *
 * Copyright (c) The copyright holder.
 *
 * Basic Wine wrapper for the Linux &#60;3rd party library&#62; so that it can be
 * used by &#60;the application&#62;
 *
 * Currently this file makes no attempt to be a full wrapper for the &#60;3rd
 * party library&#62;; it only exports enough for our own use.
 *
 * Note that this is a Unix file; please don't go converting it to DOS format
 * (e.g. converting line feeds to Carriage return/Line feed).
 *
 * This file should be built in a Wine environment as a WineLib library, 
 * linked to the Linux &#60;3rd party&#62; libraries (currently libxxxx.so and 
 * libyyyy.so)
 */

#include &#60; &#60;3rd party linux header&#62; &#62;
#include &#60;windef.h&#62; /* Part of the Wine header files */

/* This declaration is as defined in the spec file.  It is deliberately not
 * specified in terms of &#60;3rd party&#62; types since we are messing about here
 * between two operating systems (making it look like a Windows thing when
 * actually it is a Linux thing).  In this way the compiler will point out any
 * inconsistencies.
 * For example the fourth argument needs care
 */
signed short WINAPI MyProxyWinFunc (unsigned short a, void *b, void *c,
                unsigned long *d, void *e, int f, char g, unsigned char *h)
{
    unsigned short d1;
    signed short ret;

    d1 = (unsigned short) *d;
    ret = &#60;3rd party linux function&#62; (a, b, c, &#38;d1, e, g, h);
    *d = d1;

    return ret;
}

/* End of file */
        </PRE
></TD
></TR
></TABLE
>
      </P
><P
>        For a more extensive case we can use the ODBC example.  This is
        implemented as a header file 
        (<TT
CLASS="FILENAME"
>proxyodbc.h</TT
>) and the actual
        C source file (<TT
CLASS="FILENAME"
>proxyodbc.c</TT
>).  Although the file
        is quite long it is extremely simple in structure.
      </P
><P
>        <TT
CLASS="FUNCTION"
>DllMain</TT
> the function is used to initialize the DLL.
        On the process attach event the function dynamically links to the
        desired Linux ODBC library (since there are several available) and
        builds a list of function pointers.  It unlinks on the process
        detach event.
      </P
><P
>        Then each of the functions simply calls the appropriate Linux function
        through the function pointer that was set up during initialization.
      </P
></DIV
><DIV
CLASS="SECT1"
><HR><H2
CLASS="SECT1"
><A
NAME="BINDLLS-BUILDING"
>Building</A
></H2
><P
>        So how do we actually build the Wine built-in Dll?  The easiest way is
        to get Winemaker to do the hard work for us.  For the simple example we
        have two source files (the wrapper and the spec file).  We also have
        the 3rd party header and library files of course.
      </P
><P
>        Put the two source files in a suitable directory and then use 
        winemaker to create the build framework, including configure script,
        makefile etc.  You will want to use the following options of 
        winemaker:
        <P
></P
><UL
><LI
><P
>              --nosource-fix and --nogenerate-specs (requires winemaker version
              0.5.8 or later) to ensure that the two files are not modified.
              (If using an older version of winemaker then make the two files
              readonly and ignore the complaints about being unable to modify
              them).
            </P
></LI
><LI
><P
>              --dll --single-target MyWin --nomfc to specify the target
            </P
></LI
><LI
><P
>              -DMightNeedSomething -I3rd_party_include -L3rd_party_lib -lxxxx
              -lyyyy where these are the locations of the header files etc.
            </P
></LI
></UL
>
      </P
><P
>        After running winemaker I like to edit the Makefile to add the line
        CEXTRA = -Wall just before the DEFINES =.
      </P
><P
>        Then simply run the configure and make as normal (described elsewhere).
      </P
></DIV
><DIV
CLASS="SECT1"
><HR><H2
CLASS="SECT1"
><A
NAME="BINDLLS-INSTALLING"
>Installing</A
></H2
><P
>        So how do you install the proxy and ensure that everything connects up
        correctly?  You have quite a bit of flexibility in this area so what 
        follows are not the only options available.
      </P
><P
>        Ensure that the actual Linux Shared Object is placed somewhere where
        the Linux system will be able to find it.  Typically this means it 
        should be in one of the directories mentioned in the /etc/ld.so.conf
        file or somewhere in the path specified by LD_LIBRARY_PATH.  If you 
        can link to it from a Linux program it should be OK.
      </P
><P
>        Put the proxy shared object (MyWin.dll.so) in the same place as the
        rest of the built-in DLLs.  (If you used winemaker to set up your build
        environment then running "make install" as root should do that for you)
        Alternatively ensure that WINEDLLPATH includes the directory containing
        the proxy shared object.
      </P
><P
>        If you have both a Windows DLL and a Linux DLL/proxy pair then you will
        have to ensure that the correct one gets called.  The easiest way is
        probably simply to rename the windows version so that it doesn't get
        detected.  Alternatively you could specify in the DllOverrides section
        (or the AppDefaults\\myprog.exe\\DllOverrides section) of the config
        file (in your .wine directory) that the built-in version be used.  Note
        that if the Windows version Dll is present and is in the same
        directory as the executable (as opposed to being in the Windows
        directory) then you will currently need to specify the whole path to
        the dll, not merely its name.
      </P
><P
>        Once you have done this you should be using the Linux Shared Object
        successfully.  If you have problems then set the WINEDEBUG=+module
        environment variable before running wine to see what is actually happening.
      </P
></DIV
><DIV
CLASS="SECT1"
><HR><H2
CLASS="SECT1"
><A
NAME="BINDLLS-FILENAMES"
>Converting filenames</A
></H2
><P
>        Suppose you want to convert incoming DOS format filenames to their
        Unix equivalent.  Of course there is no suitable function in the true
        Microsoft Windows API, but wine provides a function for just this
        task and exports it from its copy of the kernel32 DLL.  The function
        is <TT
CLASS="FUNCTION"
>wine_get_unix_file_name</TT
> (defined in winbase.h).
      </P
></DIV
></DIV
></DIV
></BODY
></HTML
>
