Added PWNDCLASS definition.
[wine] / documentation / HOWTO-winelib
1 WineLib HOWTO
2 Version 30-Jul-2000
3
4 AUTHOR: 
5 Wilbur Dale
6 Lumin Software BV
7 Zandheuvel 52 B
8 4901 HW Oosterhout (NB)
9 The Netherlands
10
11 wilbur.dale@lumin.nl
12
13 WARNING: This HOWTO is incomplete. I expect to add to it on a weekly
14 basis until it is complete.
15
16 =====================================================================
17
18 Table of Contents
19
20    I. Introduction: Wine vs. WineLib
21
22   II. Legal Issues
23
24  III. How Much Work?
25
26   IV. File Format Conversion
27
28    V. Compiling A Simple Win32 Program 
29
30   VI. Compiling A Win32 Program With Resources
31
32  VII. DLLs
33     A. Windows executable and Windows DLL.
34     B. Windows executable and WineLib DLL.
35     C. WineLib executable and Windows DLL.
36     D. WineLib executable and WineLib DLL.
37
38 VIII. How to use MFC
39     A. Using a native MFC DLL
40     B. Compiling MFC
41
42 VIII. Trademarks
43 Windows 3.x, Windows 95, Windows 98, Windows NT are trademarks of
44 Microsoft Corporation. 
45
46 Unix is a trademark of ???? FIXME: who has the trademark this week?
47
48 CrypKey is a trademark of Kenonic Controls Ltd.
49
50 FIXME: Codewright copyright ???
51
52 All other trademarks are the property of their respective owners.
53
54 =====================================================================
55
56 I. Introduction: Wine vs. WineLib
57
58 WineLib provides the Win32 API to a non-Microsoft operating
59 system. The WineLib Win32 functions use X11 functions to perform the
60 actual drawing on the screen. Wine and WineLib are based on the same
61 set of functions that implement the Win32 API. The difference between
62 Wine and WineLib is the type of executable that is loaded into memory
63 and executed. If an executable and any associated DLLs were compiled
64 for x86 hardware running the Windows 95, 98, or Windows NT (TM)
65 operating systems, then Wine can use a special binary loader to load
66 the program and the libraries into memory and execute it. WineLib on
67 the other hand allows you to take the source for such a program and
68 DLLs and compile it into the native format of a x86 Unix or Linux
69 operating system. WineLib also allows you to partially compile the
70 program and DLLs into the native format. For example, if you use a DLL
71 from a vendor to provide some functions to your program and the vendor
72 does not give you source, then you can use the Windows version of the
73 DLL to provide the functions and compile the rest of your program in
74 the native form for your system. [1]
75
76 Windows compilers and linkers generate executables with a different
77 structure than standard compilers. Windows has two executable formats:
78 the NE format and the PE format. The NE executable format provides for
79 two entry points and the PE format provides for three entry points
80 while a standard executable has a single entry point. Usually, a NE or
81 a PE executable will use one of the entry points for your program and
82 the other entry points will print an error message and exit. However,
83 a linker can link 16 bit objects into one or both of the alternate
84 entry points of a NE or PE executable.
85
86 Standard compilers assume that the function main() exists. The entry
87 point for a standard program is constructed from the C runtime
88 library, initialization code for static variables in your program, the
89 initialization code for your classes (C++), and your function main().
90 On the other hand, windows compilers assume WinMain() exists. The
91 entry point for a windows program is constructed from the C runtime
92 library, initialization code for static variables in your program, the
93 initialization code for your classes (C++), and your function
94 WinMain(). [4]
95
96 Since main() and WinMain() have different type signatures (parameter
97 types), WineLib provides certain aids to generate code so that your
98 program can be compiled and run as written for windows. For example,
99 WineLib generates a main() to initialize the windows API, to load any
100 necessary DLLs and then call your WinMain(). Therefore, you need to
101 learn four basic operations to compile a windows program using
102 WineLib: compiling a simple program, compiling resources, compiling
103 libraries, and compiling MFC (if you will be using MFC). Each of these
104 skills or operations are explained in later sections of this HOWTO.
105
106 Before you start porting your windows code to WineLib, you need to
107 consider whether you are allowed to port your program to WineLib. As
108 you compile your program using WineLib, you will be combining software
109 from several sources and you need to ensure that the licenses for the
110 components are compatible. Hence, in the next section, we will examine
111 several legal issues.
112
113 II. Legal Issues
114
115 Disclaimer! I am not a lawyer. The purpose of this section is to make
116 you aware of potential legal problems. Be sure to read your licenses
117 and to consult your attorney.
118
119 During the compilation of your program, you will be combining code
120 from several sources: your code, WineLib code, code from your vendor's
121 DLLs (if any), and Microsoft MFC code (if used). As a result, you must
122 ensure that the licenses of all code sources are obeyed. What you are
123 allowed and not allowed to do can vary depending on how you compile
124 your program and if you will be distributing it. For example, if you
125 are releasing your code under the GPL, you cannot link your code to
126 MFC code because the GPL requires that you provide ALL sources to your
127 users. The MFC license forbids you from distributing the MFC source so
128 you can not comply with the GPL license except by not distributing you
129 program. On the other hand, if your code is released under the LGPL,
130 you cannot statically link your program to MFC and distribute it, but
131 you can dynamically link your LGPL code and MFC code and distribute
132 it.
133
134 Wine/WineLib is distributed under an X11-like license. It places few
135 restrictions on the use and distribution of Wine/WineLib code. I doubt
136 the Wine license will cause you any problems. On the other hand, MFC
137 is distributed under a very restrictive license and the restrictions
138 vary from version to version and between service packs.
139
140 If you plan on using MFC, there are three hurdles to legally using
141 MFC. The first hurdle is how to legally get MFC source code on your
142 computer. MFC source code comes as a part of Visual Studio. The
143 license for Visual Studio implies it is a single product that can not
144 be broken up into its components. The cleanest way to get MFC on you
145 system is to use a dual boot Linux box with the windows partition
146 visible to the Linux OS. Boot into windows and install Visual
147 Studio. Since Visual Studio is installed on the computer, you have not
148 broken it into its components. There may be other solutions, but I
149 think this is the easiest.
150
151 FIXME: quote relevant sections of EULA in above paragraph.
152
153 The second hurdle for MFC is the legality of compiling MFC on a
154 non-Microsoft operating system. This varies with the version of MFC.
155
156 MFC license from Visual Studio 6.0:
157
158     1.1 General License Grant. Microsoft grants to you as an
159     individual, a personal, nonexclusive license to make and use
160     copies of the SOFTWARE PRODUCT for the sole purposes of designing,
161     developing, and testing your software product(s) that are designed
162     to operate in conjunction with any Microsoft operating system
163     product. [Other unrelated stuff deleted.]
164
165 So it appears you cannot compile MFC for WineLib using this
166 license. On the other hand, Visual Studio 6.0 service pack 3 (Visual
167 Studio 5.0 is similar):
168
169     1.1 General License Grant. Microsoft grants to you as an
170     individual, a personal, nonexclusive license to make and use
171     copies of the SOFTWARE PRODUCT for the purpose of designing,
172     developing, and testing your software product(s). [Other unrelated
173     stuff deleted]
174
175 So it appears you can compile MFC for WineLib using this license.
176
177 The third hurdle is your legal right to distribute an MFC
178 library. Check the relevant section of the license on redistributables
179 and your redistribution rights. As I read the license, you only have
180 the right to distribute binaries of the MFC library if it has no debug
181 information and if you distribute it with an application that provides
182 significant added functionality to the MFC library.
183
184 FIXME: quote relevant sections of EULA in above paragraph.
185
186 Once you have examined the licenses for all of the sources used in
187 compiling your program and have decided you can legally compile you
188 program using WineLib, you should probably experiment with your
189 program running under Wine to determine how much work will be involved
190 in the port. The next section will give advice on estimating the
191 amount of work required for porting your program to WineLib.
192
193 III. How Much Work?
194
195 Wine and WineLib use the same functions to implement the windows API;
196 hence, if your program correctly runs under Wine, it should run under
197 WineLib. However, Wine/WineLib is incomplete; you may have trouble
198 running your program under Wine. Many people have successfully run many
199 programs under Wine, so there is a good chance you will have no
200 trouble.
201
202 Wine executes the binary program that was compiled for a windows
203 operating system. There are differences between the windows operating
204 system and Unix/Linux operating systems. For example, in Windows 95
205 and Windows 98, the program has direct access to the hardware. A copy
206 protection program that you purchased for your windows executable may
207 use direct hardware access to write data to the disk. Hence, you may
208 need to disable the copy protection in order to test your executable
209 under Wine.
210
211 As a specific example, CrypKey is a copy protection program we use at
212 Lumin Software. Our program does not execute under Wine with the copy
213 protection enabled. We disabled the copy protection, recompiled the
214 windows executable, and our program works fine. CrypKey also works for
215 Windows NT where it creates a service. Using Wine with the --winver
216 nt40 option "almost" gets the our program working with copy
217 protection. At a later date, we intend to either implement the system
218 calls in Wine that are missing for CrypKey or to use another copy
219 protection program that does work under Linux.
220
221 During the execution of your program, Wine prints error messages to
222 standard error. These error messages include "stubs", which are
223 windows API functions that have not been completely
224 implemented. Depending on the the system call, these could be harmless
225 or crash your program. Most of the common windows API functions have
226 already been implemented, so you should have no missing API functions
227 or only a few missing functions. If you intend to continue with the
228 port to WineLib, you will need to implement these API
229 functions. After running your program for a while, you should have a
230 good feel for the number of windows API functions that you need to
231 implement. 
232
233 FIXME: give info on Wine command line options to control error
234 messages. 
235
236 During the compilation of Wine, you can control the amount of error
237 messages and debug information that will be be generated by Wine and
238 WineLib. For the version released to your customers, you may want to
239 use the following command line to configure the Wine/WineLib
240 libraries.
241
242 ./configure --disable-debug --disable-trace
243
244 The option --disable-debug compiles out all debugging messages and the
245 option --disable-trace compile out TRACE messages. [2] 
246
247 It is not necessary for you to implement the entire documented
248 behavior of an API function in order to get your program to work. For
249 example, many API functions have pointer parameters that are NULL in
250 the common cases. If you always call the function with a NULL pointer
251 for the default behavior, you can save yourself some effort by
252 implementing a function that only works for the NULL pointer
253 parameter. If you do this, make sure you test if the parameter is
254 non-null and issue a warning for the non-null case. Also document in
255 the source that the API function is incomplete.
256
257 FIXME: give info on the FIXME (macro/function?) for partially
258 implemented API functions.
259
260 Once you have implemented an API function, submit the change back to
261 the Wine project so the next person to need the same function does not
262 need to repeat your work. Remember, someone else wrote all of the
263 other API functions that you are using, so you are benefiting from
264 their work. Let other people benefit from your work as well. If you
265 work for a company, you may need your company's permission to "give
266 away" your work.
267
268 IV. File Format Conversion
269
270 Before you can compile your program, you must deal with one major
271 difference between Windows and WineLib. Window sources are in DOS
272 format with carriage return / line feed at the end of each line of
273 text while WineLib files are in Unix format with only line feed at the
274 end of each line of text. 
275
276 The main problem with the difference between Unix and DOS format
277 source files occurs with macro line continuation. A Unix compiler
278 expects a backslash (\) followed by a newline (^J) to indict that a
279 macro is continued on the next line. However, a file in DOS format will
280 have the characters backslash (\), carriage return (^M), and newline
281 (^J). The Unix compiler will interpret the backslash (\), carriage
282 return (^M), newline (^) of a file in DOS format as a quoted carriage
283 return and newline. The Unix compiler will think the line has ended
284 and the macro is completely defined. Hence, before you compile your
285 sources, you will need to convert you DOS format sources to Unix
286 format. There are several tools such as dos2unix and tr that are
287 available to convert the format.
288
289 FIXME: get more info on dos2unix, tr, and all other such tools and
290 give example commands. Until I do [3] is a good source.
291
292 FIXME: is CR/LF conversion necessary for gcc 2.95 ?
293
294 V. Compiling A Simple Win32 Program 
295
296 Wine and WineLib are written in C as is the MS Win32 API; thus, if
297 have a program that calls only the Win32 API directly, you can compile
298 the program using a C compiler and link it with some of the WineLib
299 libraries. There are several simple examples of WineLib programs in
300 the directory libtest/ in the Wine source tree. We shall examine one
301 of these to show you how to compile a WineLib program.
302
303 The example we shall examine is hello2. If you examine hello2.c, you
304 will see it is a windows program that pops up a message box that says
305 "Hello, hello!". It can be compiled and run using a windows compiler
306 just like any other windows program. However, it can not be compiled
307 and run with a non-windows compiler. As mentioned previously, windows
308 programs have an entry point called WinMain(), while non-windows
309 compilers use an entry point of main(). Hence, we need some "glue" to
310 glue the main() entry point to the WinMain() in the windows program.
311
312 In WineLib, the glue is provided by the spec file. Spec files are used
313 in several places in Wine and WineLib to provide glue between windows
314 code and code for non-windows compilers. WineLib provides a tool
315 called winebuild in the tools/winebuild directory that converts a spec file
316 into a C file that can be compiled and linked with the windows source
317 files. If you examine hello2.spec, you will see the following:
318
319 name    hello2
320 mode    guiexe
321 type    win32
322 init    WinMain
323
324 Information on the complete format of the spec file can be found in
325 <wine>/tools/winebuild/README. Name is the name of the
326 application. Mode is the type of "glue" that winebuild needs to
327 create. Possible modes are 'dll' for a library, 'cuiexe' for a console
328 application, and 'guiexe' for a regular graphical application. Type is
329 the type of API, either win32 or win16. Win16 is supported only in
330 Wine, not WineLib, so you should use win32. Init is the function to
331 call for initialization: in this case, WinMain.
332
333 During compilation of the hello2 executable, the following command is
334 executed. 
335
336 ../tools/winebuild/winebuild -fPIC -o hello2.spec.c -spec hello2.spec
337
338 The program winebuild will generate the output file hello2.spec.c (option
339 -o hello2.spec.c) from the spec file hello2.spec (option -spec
340 hello2.spec). The option -pic specifies that winebuild should generate
341 position independent code and is only necessary for building shared
342 library files (.so files). It is not needed when building the main
343 executable spec file, but since there is no assembly code generated
344 for the main executable, it doesn't make any difference anyway. [5]
345
346 The winebuild program is used in several places in Wine as well as
347 WineLib; however, only the -spec option will be used in WineLib. The
348 output file hello2.spec.c contains main() and the glue code to
349 initialize WineLib and call WinMain().
350
351 Now the compilation of hello2 can proceed as any other compilation for
352 a program.
353
354 gcc -c -I. -I. -I../include -I../include -g -O2 -Wall  -D_REENTRANT \
355 -I/usr/X11R6/include -o hello2.o hello2.c 
356
357 FIXME: -D_REENTRANT why?
358 FIXME: explain compiler options
359
360 to compile the window program itself and 
361
362 gcc -c -I. -I. -I../include -I../include -g -O2 -Wall -D_REENTRANT \
363 -I/usr/X11R6/include -o hello2.spec.o hello2.spec.c
364
365 to compile the main() and the glue code. Finally,
366
367 gcc -o hello2 hello2.o hello2.spec.o -L../dlls  -L.. -lwine -lncurses
368 -lm  -lutil -ldl                                 
369
370 FIXME: explain linker options
371
372 will link the files into an executable. All of the steps are automated
373 with the makefile, so "make hello2" will execute all of the steps for
374 you. 
375
376 Thus, you now have the basics of compiling a simple windows
377 program. There are two more things to learn for compiling more complex
378 windows programs: windows resources and DLL dependencies. Window
379 resources are described in the next section. DLL dependencies are
380 handled by linker magic with windows compilers. Thus, in WineLib, you
381 will need to provide information about which DLLs your program
382 depends. This information is given in the spec file. For example, if
383 our hello2 program had a .wav file that it played, it would need the
384 multi-media DLL winmm. Our spec file would then be
385
386 name    hello2
387 mode    guiexe
388 type    win32
389 init    WinMain
390 import  winmm
391
392 If you need to list multiple DLLs, then the import specification can
393 appear multiple times.
394
395 FIXME: can multiple libraries appear on one import line?
396
397 VI. Compiling A Win32 Program With Resources
398
399 FIXME: to be continued.
400 Describe wrc.
401 Go through hello world example 3.
402
403 VII. DLLs
404
405 As mentioned in the introduction, Wine allows you to execute windows
406 executables and windows libraries under non-Microsoft operating
407 systems. WineLib allows you to take sources intended for the windows
408 operating system and to compile them to run as native executables
409 under a Unix/Linux operating system. With an executable and a single
410 library, there are four combinations in which to run the programs and
411 the library:
412     1. a Windows executable with a Windows DLL,
413     2. a Windows executable with WineLib DLL,
414     3. a WineLib executable with Windows DLL, and
415     4. a WineLib executable with WineLib DLL.
416 In this section, we will discuss each of these and discuss the steps
417 required to implement the executable/DLL combination. 
418
419 A. Windows executable and Windows DLL
420
421 Running a windows executable with a windows DLL is not a WineLib
422 program: it is a Wine program. If you type
423     wine program.exe
424 and the DLL is in the search path, then the windows program should run
425 using the windows DLL.
426
427 FIXME: find out what is the search path.
428
429 B. Windows executable and WineLib DLL
430
431 Running a windows executable with a WineLib DLL is also accomplished
432 using the Wine program. The source code for the DLL is compiled into a
433 Unix style shared library. When the windows executable "loads" the
434 DLL, Wine will use the shared library (.so file) instead.
435
436 At first you may wonder why you would want to run a windows executable
437 with a WineLib DLL. Such a situation implies you do not have the
438 source for the executable, but you do have the source for the
439 DLL. This is backwards from what you might expect. However, I do have
440 an example where this situation might arise.
441
442 Codewright is a popular editor in the windows world, and the
443 capabilities of Codewright can be extended by using DLLs. Since
444 Codewright is a commercial product, you do not have the source and
445 must use the windows executable with Wine. If you have written a DLL
446 to add functionality to Codewright, you have two choices: you can
447 compile the DLL using a windows compiler and use both a windows
448 executable and a windows DLL as in case A above, or you can use
449 WineLib and compile the DLL as a shared library (.so file). I have no
450 idea if Codewright actually runs under Wine, but this is an example of
451 why you might decide to use a windows executable and a WineLib
452 DLL. Many other editors and other programs use DLLs to extend their
453 functionality.
454
455 In order for Wine to use the WineLib DLL, certain glue code is need to
456 replace the linker magic that windows compilers use. As with a simple
457 executable, the winebuild program uses a spec file to generate the glue
458 code. For example, in the spec file for the DLL will look something like
459     name        winedll
460     type        win32
461     init        winedll_DllMain
462     1 cdecl _WINEbirthDay@4 ( str ) WINEbirthDay
463     2 cdecl _WINEfullName@4 ( str ) WINEfullName
464 The name is the name of the DLL. Since WineLib only supports win32,
465 the type should always be win32. The init function is the name of the
466 initialization function for the DLL. The initialization function for a
467 windows DLL is named DllMain(). You will need to rename the function
468 in the DLL source so there will not be any name clashes with the
469 DllMain() of other DLLs in you program.
470
471 The last two lines of the spec file above, provide the export
472 information for the DLL. For example, the line
473     1 cdecl _WINEbirthDay@4 ( str ) WINEbirthDay
474 says that the function at ordinal 1 uses the cdecl calling convention
475 for the parameters. The DLL export name is _WINEbirthDay@4. The
476 function takes a single parameter that is a string. Finally, the C
477 function name to be called whenever this DLL function is called is
478 WINEbirthday. You will need a function ordinal line for each function
479 in the DLL. The export name and the ordinal can be obtained from the
480 windows program dumpbin and the windows version of the DLL. See the
481 file <wine>/tools/winebuild/README for more details on the spec file
482 format.
483
484 During the the compile process, a command like
485     winebuild -fPIC -o winedll.spec.c -spec winedll.spec
486 will be executed to create the file winedll.spec.c from information in
487 the file winedll.spec. The file winedll.spec.c and winedll.c are
488 compiled into object files and used to create the shared library.
489
490 In order for the program to run, a copy of the shared library must be in
491 your EXTRA_LD_LIBRARY_PATH. For example, if your wine.conf file has
492 the following line,
493     EXTRA_LD_LIBRARY_PATH=${HOME}/wine/lib
494 then you must copy the shared library into the directory ~/wine/lib/
495 and the shared library will now be in the correct search path.
496
497 Now when you type 
498     wine program.exe
499 the program will load the shared library (.so).
500
501 C. WineLib executable and Windows DLL
502
503 Running a WineLib executable with a Windows DLL is accomplished
504 using WineLib. This situation will be common since you may have
505 purchased DLLs to use with you project and the DLL vendor may not give
506 you the source code for the DLL.
507
508 In order for WineLib to use the Windows DLL, certain glue code is
509 needed to replace the linker magic that windows compilers use. Part of
510 the glue code must be written by you. The basic idea of the glue code
511 is that you write a new DLL that consists of function pointers. Each
512 function in the DLL will consist of a call on a function pointer. For
513 example, 
514     WINEDLL_ConstString WINEDLL_INTERFACE 
515     WINEfullName( WINEDLL_ConstString handle ) {
516         return (* pWINEfullName) ( handle );
517     }
518 The initialization function for the DLL will use the function
519 LoadLibrary() to load the windows DLL and initialize the function
520 pointers using the function GetProcAddress(). 
521
522 Since Wine can use either windows DLLs or Unix shared libraries (.so),
523 the LoadLibrary() function call may have unexpected results if there
524 is a winedll.dll and a winedll.so file. Hence, the windows version of
525 the DLL should be named something like hiddenWinedll.dll and the
526 shared library should be named winedll.so. Now the shared library will
527 use LoadLibrary() to load the "hidden" DLL.
528
529 The shared library will need a spec file. Fortunately, it is simpler
530 than case B above. The spec file will look something like
531     name        winedll
532     type        win32
533     init        winedll_DllMain
534 The name is the name of the DLL. Since WineLib only supports win32,
535 the type should always be win32. The init function is the name of the
536 initialization function for the shared library. This is the function
537 that will load the "hidden" DLL and initialize the function
538 pointers. There is no need for any function ordinals unless your
539 program calls functions by the ordinal.
540
541 During the the compile process, a command like
542     winebuild -fPIC -o winedll.spec.c -spec winedll.spec
543 will be executed to create the file winedll.spec.c from information in
544 the file winedll.spec. The file winedll.spec.c and winedll.c are
545 compiled into object files and used to create the shared library.
546
547 Now that the shared library is compiled, you still need to compile
548 your program. Part of the compile process for your program will
549 consist of a spec file for you program. For example,
550     name        program
551     mode        guiexe
552     type        win32
553     init        WinMain
554     import winedll.dll
555 This spec file is similar to the spec file of the simple WineLib
556 example in part V above. The only difference is the import
557 specification that tells WineLib that the main program uses
558 winedll.dll. If this import line is not included, the "hidden" DLL
559 will not be loaded and the function pointers will not be initialized.
560
561 During the the compile process, a command like
562     winebuild -fPIC -o program.spec.c -spec program.spec
563 will be executed to create the file program.spec.c from information in
564 the file program.spec. The file program.spec.c and your source code are
565 compiled into object files and used to create the executable.
566
567 D. WineLib executable and WineLib DLL.
568
569 Running a WineLib executable with a WineLib DLL is accomplished using
570 WineLib. The source for the DLL will be combined with a spec file to
571 generate the shared library. Likewise, the source for your program and
572 a spec file will be combined to create the executable. In the source
573 for the DLL, you should change the name of DllMain() to a name like
574 winedll_DllMain() so that there will not be a name clash with other
575 initialization functions for other DLLs.
576
577 The shared library's spec file is like case C above. The spec file
578 will look something like
579     name        winedll
580     type        win32
581     init        winedll_DllMain
582 The init function is the name of the initialization function for the
583 shared library (what you renamed DllMain to). There is no need for any
584 function ordinals unless your program calls functions by the ordinal.
585
586 During the the compile process, a command like
587     winebuild -fPIC -o winedll.spec.c -spec winedll.spec
588 will be executed to create the file winedll.spec.c from information in
589 the file winedll.spec. The file winedll.spec.c and the source code for
590 your DLL are compiled into object files and used to create the shared
591 library.
592
593 Compiling your program is exactly like case C above. For example, the
594 spec file for you program will look something like
595     name        program
596     mode        guiexe
597     type        win32
598     init        WinMain
599     import winedll.dll
600
601 During the the compile process, a command like
602     winebuild -fPIC -o program.spec.c -spec program.spec
603 will be executed to create the file program.spec.c from information in
604 the file program.spec. The file program.spec.c and your source code are
605 compiled into object files and used to create the executable.
606
607 VIII. How to use MFC
608     A. Using a native MFC DLL
609     B. Compiling MFC
610
611 FIXME: to be continued.
612
613 =====================================================================
614 References
615
616 Until this HOWTO is complete, I will document who gives me what
617 information. 
618
619 Reference [1] 
620 From: Patrik Stridvall <ps@leissner.se>
621 To: "'wilbur.dale@lumin.nl'" <wilbur.dale@lumin.nl>,
622 Date:   Mon, 5 Jun 2000 14:25:22 +0200 
623
624 First of all WineLib suppport for Win16 has been discontinued
625 for quite some time, because:
626
627 1. It is difficult for us to support and it is impossible
628    to do so prefectly without special compiler support,
629    because of memory layout issues. For example Win16 int
630    is 16-bit and data is aligned 16-bit.
631 2. It is in almost all cases easier to port a
632    Win16 application to Win32.
633
634 A minor detail, I personally would prefer that Wine and WineLib
635 was always used in the uppercase W and uppercase L variant,
636 instead of, as in your document, sometime one variant, sometimes
637 another.
638
639 Reference [2] 
640
641 The exact options for controlling error messages mentioned in the
642 reference are apparently incorrect, but may have been correct for some
643 earlier version of Wine.
644
645 From: michael cardenas <mbc@deneba.com>
646 To: wilbur.dale@lumin.nl
647 Date:   Mon, 5 Jun 2000 13:19:34 -0400
648
649 a few things you should mention...
650
651 - you can compile resources as a dll under windows and then load the dll
652 with wine. That's what we do for canvas. This is probably not ideal, but
653 most of my problems porting were in the code. We very seldomly have to
654 change the resources for the porting process. But wrc does work for most
655 cases...
656
657 - the error messages can be turned off or turned up with options to
658 configure like --enable-trace-msgs=wireoff or --enable-trace-msgs=wireon .
659 Take a look at configure.
660
661 - you probably want to compile your WineLib with --disable-debugger, at
662 least for the release version of your app.
663
664 Reference [3] 
665 http://fgouget.free.fr/wine/winelib-en.shtml
666
667 Reference [4]
668 Date: Wed, 21 Jun 2000 10:34:10 +0200
669 From: Rob Carriere <rob.carriere@lumin.nl>
670 To: Wilbur N Dale <wilbur.dale@lumin.nl>
671 Subject: WineLib-HOWTO comments
672
673 Hello Wilbur,
674
675 Some picking of nits.  It reads right well.
676
677 Some of Windows xyz are registered trade marks, other are vanilla:
678 Microsoft: Registered
679 Windows NT: Registered
680 Windows (95,98): plain
681
682 A Windows compiler does NOT generate a fake main.  Instead, the
683 executable file format provides for 2 (NE) or 3 (PE) entry points.
684 One of these is your program, the other(s) are normally filled with
685 stubs that print an error message and exit.  It is possible to instruct
686 the _linker_ to link 16-bit objects into one or both of the alternate
687 entry points, and create a fat binary.
688
689 At the C/C++ level, your statement about WinMain() is correct.  Of
690 course the actual entry point first inits run time lib etc, and then
691 calls the C/C++ level entry, but that is also true for main() in the
692 standard setup.  It may be important to regurgitate this info here,
693 though, because some of the fun things that can happen with multiple
694 run time libs and DLLs occur at this level.
695
696 Line 86: I only need to know how compile MFC if I use it... :-)
697
698
699 Best regards,
700  Rob                          mailto:rob.carriere@lumin.nl
701
702 Reference [5]
703 To: wilbur.dale@lumin.nl
704 Subject: Re: tool/build questions
705 From: Alexandre Julliard <julliard@winehq.com>
706 Date:   13 Jun 2000 20:06:23 -0700
707
708 "Wilbur N. Dale" <wilbur.dale@lumin.nl> writes:
709
710 > 2. tools/build for WineLib users -- is there ever a need to not specify -pic?
711
712 -pic is only necessary for building .so files, so it's not needed when
713 building the main executable spec file (but since there is no assembly
714 code generated for the main exe it doesn't make any difference anyway).
715
716 -- 
717 Alexandre Julliard
718 julliard@winehq.com
719
720 Reference [6]
721 Wine Weekly News #51 (2000 Week 28)
722
723 Events, progress, and happenings in the Wine community for 
724 July 10, 2000. 
725
726 Uwe Bonnes and Ove Kaven also reminded of some tools to generate under
727    Linux some Windows executables:
728      * Cygwin/Mingw: as native Linux apps
729      * LCC-Win32: run with the help of Wine
730      * Borland C++ 5.5: command line version available for free (after
731        registering to Borland users' database)
732        
733 =====================================================================
734
735 The information included here is from various Wine-devel posting and
736 private e-mails. I am including them so that any one starting on MFC
737 will have some documentation. Glean what you can and good luck.
738
739 Before I write more detailed info on compiling MFC I have three
740 questions. The info I have mentions three problems:
741
742     1. Wine header files---what is the status of this? Do changes need
743     to be made in the headers and if so, do I submit the changes back
744     into Wine cvs? Do the changes need #ifdef for C vs. C++
745     compilation? 
746
747     Francois Gouget <fgouget@psn.net> has been doing a lot of work in
748     this area. It should be a lot easier to compile using C++ now and to
749     compile MFC.
750
751     2. DOS format files <CR/LF> and no case distinction in
752     filenames. Do the extensions Corel made to gcc 2.95 handle this?
753     If so, how?
754
755     3. Microsoft extensions to the C++ syntax. Do the extensions Corel
756     made to gcc 2.95 handle this? If so, how?
757
758 If you have info that needs to be added, send me email at
759 <wilbur.dale@lumin.nl> and I will add it.
760
761 =====================================================================
762
763 THANKS
764
765 Most of the information in this file came from postings on
766 <Wine-devel@Winehq.com> and from private e-mails. The following people
767 contributed information for this document and I thank them for their
768 time and effort in answering my questions. I also want to thank them
769 for encouraging me to attack the MFC problem. 
770
771 CONTRIBUTERS:
772
773     Damyan Ognyanoff <Damyan@rocketmail.com>
774     Gavriel State <gav@magmacom.com>
775     Ian Schmidt <ischmidt@cfl.rr.com>
776     Jeremy White <jwhite@codeweavers.com>
777
778
779 From: Ian Schmidt <ischmidt@cfl.rr.com>
780 Subject: Re: WineLib and MFC
781
782 "Wilbur N. Dale" wrote:
783
784 > What is the status of MFC under WineLib?
785
786 I don't know precisely. Corel has done more MFC work than anyone (all
787 of their applications which they are porting are MFC-based), and
788 reportedly they have MFC itself compiled. I was just trying to get a
789 moderately simple MFC-using app to compile, with moderate success
790 (there are still some problems with MFC's headers after my patch, but
791 at least they don't appear to be Wine's fault :) I did not try to
792 compile MFC itself.
793
794 > Which versions of MFC, if any?
795
796 I have no idea what version Corel uses. As noted in my patch, I was
797 fiddling with the headers for MFC 6 (from Visual C++ 6.0 Service Pack
798 3). Most of the stuff my patch addressed was for newer IE 5-related
799 features, so I'd guess MFC 5 (VC++ 5.0) is likely what they used.
800
801 > Is there any documentation on how to compile MFC for WineLib?  If so
802 > where?
803
804 Not that I know of.
805
806 > I have started to compile programs using WineLib (hello.c last
807 > Sunday) and expect to be ready to start compiling MFC in a couple of
808 > weeks. If documentation is not available on compiling MFC, I am
809 > willing to write it.
810
811 Documentation would be a Good Thing, as WineLib in general is grossly
812 underdocumented right now. Here's a few tips I discovered to get you
813 started:
814
815 - First off, run all the MFC headers (and source too if you try it)
816 through a utility to strip out the DOS carriage returns. They cause
817 havoc with GCC when it sees one after a line that ends with a \ (and
818 MFC has many macros in it's headers that meet that description). If
819 you don't have one, do a Google search on "fromdos" and you should
820 locate some source (or it's fairly easy to make your own).
821
822 - Use GCC 2.95.2, and the -fpermissive flag to make it less picky.
823 2.95.2 has some VC++-compatibility features that Corel paid for, and I
824 believe more are forthcoming in future GCCs.
825
826 - Use -I to add whereever you have the MFC headers at to your include
827 path, as MFC apps typically use #include <> to access them rather than
828 "".
829
830 - Be prepared to have to rename and/or symlink headers, unless you
831 compile on a case-insensitive filesystem :)
832
833 - When you make install Wine it seems not to include all it's headers
834 in /usr/local/include/Wine. To have any chance at getting MFC going
835 you'll want to use -I to add the include/ directory from the Wine
836 source tarball to the path so it can grab everything.
837
838 Sorry I can't help you more, but good luck!
839
840 -Ian Schmidt
841 ischmidt@cfl.rr.com
842
843
844 From: Jeremy White <jwhite@codeweavers.com>
845 Subject: Re: RFC: Wine 1.0
846
847 "Wilbur N. Dale" wrote:
848 > > Further, we have successfully built MFC after making only
849 > > a modest set of changes to it, even with older
850 > > versions of g++.
851
852 > Lumin Software is about to use WineLib to port a window program to linux. A
853 > couple of years ago we thought we had to make a modification to MFC for one
854 > of our projects and we had problems getting MFC to compile under MS Visual C++.
855 > After much wailing and gnashing of teeth, we gave up and did things another
856 > way. After this bad experience, we were wondering --- approximately how many
857 > man-hours did you spend compiling and changing MFC ?
858
859     Urk. I misspoke. None of the developers here that I thought
860 had working versions of MFC with Wine have working versions any
861 longer. So, it may be a bit trickier than I led you to believe.
862
863     We have it working pretty reliably with TWine, but not 
864 quite so cleanly (yet) with Wine. However, it really shouldn't
865 be too difficult, and this is what I can remember of the process:
866
867         1. If you use a very modern version of gcc (2.95.2 or higher),
868             I believe you will need to add the -relaxed flag to
869             have any hope of compiling.
870
871         2. If you use an earlier version of gcc, you will need to
872             adjust the many anonymous structs/unions that MFC supplies.
873             We prefer this approach, because requiring very
874             modern gcc implementations seems harsh to us.
875
876         3. You will need to adjust for the many type differences
877             between MFC intrinsic types and the types supplied by Wine.
878             For example, I believe that MFC expects a HANDLE to
879             be compatible with certain scalar types, (and it is
880             under Windows/VC, but is not with Wine/gcc).
881
882         4. The key procedure:  add many -DNO_XXX flags to the
883             makefile. If you start with Microsofts make file
884             for MFC, convert it into a Wine makefile, and then turn
885             on many of the flags they list there (of the form -DNO_XXX),
886             your life will get much easier. Once you get it working
887             with a few -DNO_XXX flags, you can go back and add them
888             back in.
889
890         5. The best resource:  you need someone who knows C++ very,
891             very well. You occassionaly run into very obscure C++
892             problems where MS has extended the C++ standard and
893             gcc has not. It really helps to have a guru on hand
894             when you hit those.
895
896
897 I hope this helps. Sorry for the earlier deceptive post.
898
899 Jeremy
900
901 From: Gavriel State <gav@magmacom.com>
902 Subject: Re: MFC questions
903
904 "Wilbur N. Dale" wrote:
905
906 > 1. Compile MFC. Several years ago we (Lumin Software) tried to
907 > compile MFC.  The attempt failed and we found another way to do what
908 > we wanted. MS documentation states that compiling MFC was
909 > deliberately made difficult.  Considering my experience with stuff
910 > they call "easy" I am not looking forward to compiling MFC. We are
911 > currently using Visual Studio 5 for windows development.
912
913 At Corel, we had MFC compiled and running sample apps in WineLib in
914 late 1998. It's mostly a question of the Wine headers, which weren't
915 originally up to snuff. We did quite a bit of work on them, and most
916 of those changes have been contributed back to WineHQ, so it should be
917 pretty easy now. The other thing that was a big deal was getting the
918 startup code working properly - since MFC needs to initialize static
919 data *after* WineLib gets initialized. I believe that that issue has
920 been addressed now on the WineHQ side with some of the work done on
921 the .spec file tools recently.
922
923 -Gav
924
925 -- 
926 Gavriel State
927 CEO
928 TransGaming Technologies Inc.
929 gav@transgaming.com
930
931 From: Jeremy White <jwhite@codeweavers.com>
932 Subject: Re: MFC questions
933
934 "Wilbur N. Dale" wrote:
935 [snip]
936 > 1. Compile MFC. Several years ago we (Lumin Software) tried to
937 > compile MFC.  The attempt failed and we found another way to do what
938 > we wanted. MS documentation states that compiling MFC was
939 > deliberately made difficult.  Considering my experience with stuff
940 > they call "easy" I am not looking forward to compiling MFC. We are
941 > currently using Visual Studio 5 for windows development.
942
943 Wilbur, I personally think that this is the 'right' approach, although
944 approach #2 may prove faster.
945
946 Despite your previous experience, and despite my earlier incorrect
947 statements, I think that this is simpler than you fear. It's one of
948 those tasks that's darkest before the storm - you spend all of your
949 energy getting all the include files to work. Once you have *one*
950 object file, the rest go much more quickly (alright, getting it to
951 link is also a hairball of a job, but it's tractable <g>).
952
953 If you're not in a hurry, getting MFC to compile, and having a
954 documented procedure for compiling it is on our agenda for the
955 relatively near future (see the Wine 1.0 task list).
956
957 Jer
958
959 p.s. Stick with Visi C++ 5. IMHO its MFC license is cleaner than that
960 of VC 6.
961
962 From: Gavriel State <gav@magmacom.com>
963 Subject: The MSVC++ 6.0 license
964
965 Jeremy White wrote:
966 > p.s. Stick with Visi C++ 5. IMHO its MFC license is cleaner than that
967 > of VC 6.
968
969 Actually, I just picked up a copy of MSVC 6.0 and it appears that they
970 changed the license between the original release and the Service Pack
971 3 release - they removed the bit in section 1.1 about requiring that
972 you be developing your software product only for use with a Microsoft
973 OS.  In any case, even the original license explicitly says that the
974 MFC redistribution rights are *in addition* to the usage rights in
975 section 1.1.
976
977 The relevant portion of the original EULA:
978
979  1.1    General License Grant. Microsoft grants to you as an individual, a
980  personal, nonexclusive license to make and use copies of the SOFTWARE 
981  PRODUCT for the sole purposes of designing, developing, and testing your
982  software product(s) that are designed to operate in conjunction with 
983  any Microsoft operating system product. [Other unrelated stuff deleted]
984
985 >From the SP3 EULA:
986
987  3.     Section 1.1 of the EULA is deleted in its entirety and replaced 
988  with the following:
989
990  1.1    General License Grant. Microsoft grants to you as an individual, a 
991  personal, nonexclusive license to make and use copies of the SOFTWARE 
992  PRODUCT for the purpose of designing, developing, and testing your 
993  software product(s). [Other unrelated stuff deleted]
994
995 Disclaimer - I am not a lawyer, but I've spent lots of time with them 
996 investigating software licenses.
997
998  -Gav
999
1000 -- 
1001 Gavriel State
1002 CEO
1003 TransGaming Technologies Inc.
1004 gav@transgaming.com
1005
1006 From: Damyan Ognyanoff <Damyan@rocketmail.com>
1007 Subject: Need a hint
1008
1009 Hi,
1010
1011 I manage to build mfc42 as .so library and a application using it (as
1012 a .so library too). I execute it using simple loader which is linked
1013 to Wine and I load my application in it's WinMain routine. The
1014 problem is how clearly to unload mfc and my application (to invoke
1015 mfc's destructors before loader is terminated) All is fine except that
1016 there is a "zombi" reference to code in shared library which is
1017 invoked in Wine code and generate GPF. debugger stops somewhere in
1018 aplication's InitInstance !!! - and the stack is broken so I can't
1019 catch where exactly the problem is. Any hints are welcome. I'm using
1020 Wine-2000517 shapshot downloaded form Wine.datapary.no 
1021
1022 TNX.
1023
1024 Damyan
1025 p.s.
1026 If any of You is interested in details I can share my
1027 experience.
1028
1029 WND comment:
1030     Francois Gouget <fgouget@psn.net> has been doing a lot of work in
1031     the  headers of wine. It should be a lot easier to compile using
1032     C++ now and to compile MFC. Many of the actions needed in the
1033     following email are not needed any more.
1034
1035 From: Damyan Ognyanoff <Damyan@rocketmail.com>
1036 Subject: Re: Wine MFC info request
1037
1038 hi,
1039 my MFC is from VC6.0 with SP3
1040 MFC Bulid: (form  afxbld_.h)
1041     #define _MFC_BUILD 8447
1042     #define _MFC_USER_BUILD "8447"
1043     #define _MFC_RBLD 0
1044 mfcdll.rc
1045     FILEVERSION       6,0,_MFC_BUILD,_MFC_RBLD
1046     PRODUCTVERSION    6,0,0,0
1047
1048 Hints:
1049     1. Wine include files
1050
1051 In some of them you will find error about '__attribute__' all kinds of
1052 similar errors can be fixed using proper typedefs first example :
1053
1054 typedef BOOL (CALLBACK *DLGPROC)(HWND,UINT,WPARAM,LPARAM);
1055
1056 must be converted to
1057
1058 typedef BOOL CALLBACK (*DLGPROC)(HWND,UINT,WPARAM,LPARAM);
1059
1060 and the second kind is something like
1061
1062 TYPE* WINAPI SomeFunction(HWND param1,UINT param2);
1063
1064 The problem here is a TYPE* or TYPE& (in some of mfc files) the
1065 workaround is to declare a type before:
1066
1067 typedef TYPE* TYPEPtr; 
1068
1069 or
1070
1071 typedef TYPE& TYPERef;
1072
1073 and declaration will look like:
1074
1075 TYPEPtr WINAPI SomeFunction(HWND param1,UINT param2);
1076
1077 note: don't miss a 'struct' when you define struct type pointers. I
1078 miss it and get a lot of problems compiling MFC:
1079
1080 >>
1081 struct _TEB;
1082 typedef !!!struct!!! _TEB* P_TEB;
1083 extern inline P_TEB WINAPI NtCurrentTeb(void);
1084 <<
1085
1086 Those conversions are semanticaly the same as above but g++ compile
1087 them and generate proper code to invoke __stdcall kind of functions
1088
1089 in some of Wine/obj_XXX.h files: Wine/obj_base.h - there are a lot of
1090 defines's that are used to declare a COM interfaces
1091
1092 #define ICOM_METHOD(ret,xfn) \
1093      public: virtual ret (CALLBACK xfn)(void) = 0;
1094
1095 will be (for all of them that are related to C++ (watch #ifdef's
1096 carefully)):
1097
1098 #define ICOM_METHOD(ret,xfn) \
1099      public: virtual ret CALLBACK (xfn)(void) = 0;
1100
1101 and the second tip is an error when compiler stops on line like:
1102  
1103    ICOM_DEFINE(ISomeInterfase,IUnknown)
1104
1105 watch method declarations above to find something like:
1106
1107 ICOM_METHOD1(TYPE*,MethodName, DWORD,dwParam)
1108
1109 and replace TYPE* with proper TYPEPtr type. In many cases You will see
1110 void* which can be replaced simply by LPVOID.
1111
1112 qthere are several errors related to anonymous structs and unions but
1113 they can be avoided with proper - #ifdef __cplusplus
1114
1115 This is all about Wine headers I think. If you find something that I
1116 miss type a line of mail to me.
1117
1118 2. MFC
1119 The rules are the same with some new issues:
1120
1121 virtual BOOL Method1(int param1, BOOL (CALLBACK *param2)
1122 (HWND,UINT,WPARAM,LPARAM));
1123
1124 don't compile. I remove a function pointer declaration
1125 outside method:
1126
1127 typedef BOOL CALLBACK
1128 (*param2Type)(HWND,UINT,WPARAM,LPARAM);
1129
1130 virtual BOOL Method1(int param1, param2Type param2);
1131
1132 I didn't apply this technique to a operator new
1133 definitions:
1134
1135         void* AFXAPI operator new(size_t nSize);
1136
1137 so i remove AFXAPI from these declarations:
1138
1139 I got some missed #defines from commctrl.h and I added
1140 them form VC6.0 include.
1141
1142 these are my defines form Makefile which I used to
1143 compile MFC
1144
1145 -DTWINE_NO_CMONIKER \ -- this is related to exclude
1146 CMonikerFile 
1147 -D__urlmon_h__ \ -- Wine didn't have URL interfaces 
1148 -D_AFX_NO_OLEDB_SUPPORT \
1149 -D_WIN32  \
1150 -DNOWIN98  \ -- this is used to exclude all
1151 unimplemented classes from commctrl 
1152 -D_AFX_PACKING \
1153 -D_AFX_NO_DHTML_SUPPORT \
1154 -D_AFX_NO_SOCKET_SUPPORT \
1155 -D_AFX_NO_SYNC_SUPPORT \
1156 -D_AFX_NO_OCX_SUPPORT  \
1157 -D_AFX_PORTABLE \
1158 -D_AFX_OLD_EXCEPTIONS \
1159 -D_AFX_NO_SOCKET_SUPPORT \
1160 -D_AFX_NO_DEBUG_CRT \
1161 -D_AFX_NO_DAO_SUPPORT \
1162 -D_AFX_NO_OCC_SUPPORT \
1163 -D_AFX_NO_INET_SUPPORT \
1164 -D_AFX_NO_RICHEDIT_SUPPORT  \
1165 -D_X86_ \
1166 -DLONGHANDLES
1167
1168 may be you will try to enable some of features of mfc I tested only
1169 -D_AFX_NO_OCC_SUPPORT but got missing interfaces from Wine
1170
1171 in file afxcom_.h
1172 - _CIP<_Interface, _IID>::~_CIP<_Interface, _IID>()
1173 + _CIP<_Interface, _IID>::~_CIP()
1174
1175 in file afxtempl.h
1176 -       BOOL Lookup(BASE_CLASS::BASE_ARG_KEY key,
1177 VALUE& rValue) const
1178 -               { return BASE_CLASS::Lookup(key,
1179 (BASE_CLASS::BASE_VALUE&)rValue); }
1180 +       BOOL Lookup(typename BASE_CLASS::BASE_ARG_KEY
1181 key, VALUE& rValue) const
1182 +               { return BASE_CLASS::Lookup(key,
1183 (typename BASE_CLASS::BASE_VALUE&)rValue); }
1184
1185 and all releated errors can be fixed in this way.
1186
1187 3. spec file
1188     name        mfc42
1189     type        win32
1190     rsrc        mfc42
1191
1192     10 stdcall WinMain(long long ptr long) WinMain
1193
1194 4. linking 
1195     use -rdynamic wnen link libmfc.so to get ARGV and
1196 ARGC from loader
1197     
1198 5. I didn'n build a extension dll with Wine but I suspect that there
1199 will be some problems related to a chaining Runtime classes form MFC
1200 to a new dll
1201
1202 6. build your app as a MODULE too.
1203
1204 7. make a loader and in it's _WinMain:
1205 ... includes are here
1206 iint PASCAL (*winMain)(HINSTANCE,HINSTANCE,LPSTR,int) =
1207 0;
1208 my app uses these to manage filenames
1209 VOID __cdecl (*_splitpath1)(LPCSTR path, LPSTR drive,
1210 LPSTR directory, LPSTR filename, LPSTR extension ) =
1211 NULL;
1212 VOID __cdecl _splitpath(LPCSTR path, LPSTR drive,
1213 LPSTR directory, LPSTR filename, LPSTR extension )
1214 {
1215     if (_splitpath1)
1216         _splitpath1(path, drive, directory, filename,
1217 extension );
1218 }
1219 VOID __cdecl (*_makepath1)(LPSTR path, LPCSTR drive,
1220 LPCSTR directory, LPCSTR filename, LPCSTR extension )
1221 = NULL;
1222 VOID __cdecl _makepath(LPSTR path, LPCSTR drive,
1223 LPCSTR directory, LPCSTR filename, LPCSTR extension )
1224 {
1225     if (_makepath1)
1226         _makepath1(path, drive, directory, filename,
1227 extension);
1228 }
1229 int PASCAL _WinMain(HINSTANCE h,HINSTANCE h1,LPSTR
1230 lpszCmdParam,int c)
1231 {
1232   HINSTANCE hInstance,hins,hlib,htst,hform,himag,hexe;
1233         int retv;
1234
1235         hins = LoadLibrary("CRTDLL.DLL");
1236         _splitpath1 = GetProcAddress(hins,
1237 "_splitpath");
1238         _makepath1 = GetProcAddress(hins,
1239 "_makepath");
1240         hins = LoadLibrary("COMCTL32.DLL");
1241         hins = LoadLibrary("COMDLG32.DLL");
1242
1243
1244         hins = dlopen("libmfc42.so",2);
1245         hlib = LoadLibrary("mfc42");
1246         himag = dlopen("libmxformatslib.so",2);
1247         hform = LoadLibrary("mxformatslib");
1248         hexe = dlopen("libmxpaint.so",2);
1249         htst = LoadLibrary("mxpaint");
1250
1251         winMain = GetProcAddress(hlib, "WinMain");
1252         if (winMain)
1253         {
1254           retv = winMain (htst,    // note the > htst
1255 < HERE
1256                   0,            
1257                   lpszCmdParam, 
1258                   SW_NORMAL);   
1259         }
1260     FreeLibrary(htst);
1261     FreeLibrary(hform);
1262     FreeLibrary(hlib);
1263     dlclose(hexe);
1264     dlclose(himag);
1265     dlclose(hins);
1266     return retv;
1267 }
1268 the spec for loader is:
1269 name    c10
1270 mode    guiexe
1271 type    win32
1272 init    _WinMain
1273
1274 please find attached a Makefile which i use to build
1275 MFC
1276
1277 Regards 
1278 Damyan.
1279
1280  LocalWords:  WineLib HOWTO Jul vs DLLs DLL MFC NT FIXME CrypKey Kenonic API TM
1281  LocalWords:  Codewright NE PE WinMain GPL LGPL EULA nonexclusive winver nt dos
1282  LocalWords:  redistributables unix tr CR LF gcc libtest winebuild pic fPIC dll
1283  LocalWords:  guiexe init cuiexe lwine lncurses lm lutil ldl wav winmm wrc lcc
1284  LocalWords:  dllExamples WindowsExeWindowsDLL WindowsExeWineDLL WineExeWineDLL
1285  LocalWords:  WineExeWindowsDLL Borland URL's cd distclean DllMain winemain exe
1286  LocalWords:  winedll cdecl WINEbirthDay str WINEfullName WINEbirthday libtool
1287  LocalWords:  proost conf LD libwinedll Gouget docs dumpbin ConstString
1288  LocalWords:  pWINEfullName LoadLibrary GetProcAddress hiddenWinedll