2 <title id="mfc.title">Dealing with the MFC</title>
4 <sect1 id="mfc-introduction">
5 <title id="mfc-introduction.title">Introduction</title>
7 To use the MFC in a Winelib application you will first have to
8 recompile the MFC with Winelib. In theory it should be possible to
9 write a wrapper for the Windows MFC as described in
10 <xref linkend="bindlls" endterm="bindlls.title">. But in practice
11 it does not seem to be a realistic approach for the MFC:
16 the huge number of APIs makes writing the wrapper a big task in
22 furthermore the MFC contain a huge number of APIs which are tricky
23 to deal with when making a wrapper.
28 even once you have written the wrapper you will need to modify
29 the MFC headers so that the compiler does not choke on them.
34 a big part of the MFC code is actually in your application in
35 the form of macros. This means even more of the MFC headers have
36 to actually work to in order for you to be able to compile an
37 MFC based application.
42 This is why this guide includes a section dedicated to helping you
43 compile the MFC with Winelib.
47 <sect1 id="mfc-legal-issues">
48 <title id="mfc-legal-issues.title">Legal issues</title>
50 (Extracted from the HOWTO-Winelib written by Wilbur Dale
51 <wilbur.dale@lumin.nl>)
54 The purpose of this section is to make you aware of potential legal
55 problems. Be sure to read your licenses and to consult your lawyers.
56 In any case you should not consider the remainder of this section to
57 be authoritative since it has not been written by a lawyer.
60 Well, let's try to have a look at the situation anyway.
63 During the compilation of your program, you will be combining code
64 from several sources: your code, Winelib code, Microsoft MFC code,
65 and possibly code from other vendor sources. As a result, you must
66 ensure that the licenses of all code sources are obeyed. What you are
67 allowed and not allowed to do can vary depending on how you combine
68 the code and if you will be distributing it. For example, if you
69 are releasing your code under the GPL or LGPL, you cannot use MFC
70 because these licenses do not allow covered code to depend on
71 libraries with non-compatible licenses.
72 There is a workaround - in the license for your
73 code you can make an exception for the MFC library.
75 <ulink url="http://www.gnu.org/licenses/gpl-faq.html">The GNU GPL FAQ</ulink>.
78 Wine/Winelib is distributed under the GNU Lesser General Public
79 License. See the license for restrictions on the modification and
80 distribution of Wine/Winelib code. In general it is possible to
81 satisfy these restrictions in any type of application.
82 On the other hand, MFC
83 is distributed under a very restrictive license and the restrictions
84 vary from version to version and between service packs. There are
85 basically three aspects you must be aware of when using the MFC.
88 First you must legally get MFC source code on your computer. The MFC
89 source code comes as a part of Visual Studio. The license for
90 Visual Studio implies it is a single product that can not
91 be broken up into its components. So the cleanest way to get MFC on
92 your system is to buy Visual Studio and install it on a dual boot
96 Then you must check that you are allowed to recompile MFC on a
97 non-Microsoft operating system! This varies with the version of MFC.
98 The MFC license from Visual Studio 6.0 reads in part:
102 1.1 General License Grant. Microsoft grants to you as an
103 individual, a personal, nonexclusive license to make and use
104 copies of the SOFTWARE PRODUCT for the sole purposes of designing,
105 developing, and testing your software product(s) that are designed
106 to operate in conjunction with any Microsoft operating system
107 product. [Other unrelated stuff deleted.]
111 So it appears you cannot even compile MFC for Winelib using this
112 license. Fortunately the Visual Studio 6.0 service pack 3 license
113 reads (the Visual Studio 5.0 license is similar):
117 1.1 General License Grant. Microsoft grants to you as an
118 individual, a personal, nonexclusive license to make and use
119 copies of the SOFTWARE PRODUCT for the purpose of designing,
120 developing, and testing your software product(s). [Other unrelated
125 So under this license it appears you can compile MFC for Winelib.
128 Finally you must check whether you have the right to distribute an
129 MFC library. Check the relevant section of the license on
130 <quote>redistributables and your redistribution rights</quote>. The
131 license seems to specify that you only have the right to distribute
132 binaries of the MFC library if it has no debug information and if
133 you distribute it with an application that provides significant
134 added functionality to the MFC library.
135 <!-- FIXME: quote relevant sections of EULA in above paragraph. -->
139 <sect1 id="mfc-compiling">
140 <title id="mfc-compiling.title">Compiling the MFC</title>
142 Here is a set of recommendations for getting the MFC compiled with
146 We recommend running winemaker in
147 '<option>--interactive</option>' mode to specify the right
148 options for the MFC and the ATL part (to get the include paths
149 right, to not consider the MFC MFC-based, and to get it to
150 build libraries, not executables).
153 Then when compiling it you will indeed need a number of
154 <literal>_AFX_NO_XXX</literal> macros. But this is not enough
155 and there are other things you will need to
156 '<literal>#ifdef</literal>-out'. For instance Wine's richedit
157 support is not very good. Here are the AFX options I use:
161 #define _AFX_PORTABLE
162 #define _FORCENAMELESSUNION
163 #define _AFX_NO_DAO_SUPPORT
164 #define _AFX_NO_DHTML_SUPPORT
165 #define _AFX_NO_OLEDB_SUPPORT
166 #define _AFX_NO_RICHEDIT_SUPPORT
170 You will also need custom ones for
171 <function>CMonikerFile</function>, <function>OleDB</function>,
172 <function>HtmlView</function>, ...
175 We recommend using Wine's msvcrt headers (<literal>-isystem
176 $(WINE_INCLUDE_ROOT)/msvcrt</literal>), though it means you
177 will have to temporarily disable winsock support
178 (<literal>#ifdef</literal> it out in
179 <filename>windows.h</filename>).
182 You should use g++ compiler more recent than g++ 2.95. g++
183 2.95 does not support unnamed structs while the more recent
184 ones do, and this helps a lot. Here are the options worth
189 <literal>-fms-extensions</literal> (helps get more code
195 <literal>-fshort-wchar -DWINE_UNICODE_NATIVE</literal>
196 (helps with Unicode support)
201 <literal>-DICOM_USE_COM_INTERFACE_ATTRIBUTE</literal>
202 (to get the COM code to work)
208 When you first reach the link stage you will get a lot of
209 undefined symbol errors. To fix these you will need to go back
210 to the source and <literal>#ifdef</literal>-out more code
211 until you reach a 'closure'. There are also some files that
212 don't need to be compiled.
215 Maybe we will have ready-made makefile here someday...
219 <sect1 id="mfc-using">
220 <title id="mfc-using.title">Using the MFC</title>
224 Specific winemaker options,
225 the configure options,
226 the initialization problem...
231 <!-- Keep this comment at the end of the file
234 sgml-parent-document:("winelib-user.sgml" "book" "chapter" "")