Moved system metrics definitions to winuser.h.
[wine] / documentation / HOWTO-winelib
1 WineLib HOWTO
2 Version 11-Jun-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. Native DLL.
34     B. so DLL.
35     C. elfDLL.
36     D. resource 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 All other trademarks are the property of their respective owners.
51
52 =====================================================================
53
54 I. Introduction: Wine vs. WineLib
55
56 WineLib provides the Win32 API to a non-Microsoft operating
57 system. The WineLib Win32 functions use X11 functions to perform the
58 actual drawing on the screen. Wine and WineLib are based on the same
59 set of functions that implement the Win32 API. The difference between
60 Wine and WineLib is the type of executable that is loaded into memory
61 and executed. If an executable and any associated DLLs were compiled
62 for x86 hardware running the Windows 95, 98, or Windows NT (TM)
63 operating systems, then Wine can use a special binary loader to load
64 the program and the libraries into memory and execute it. WineLib on
65 the other hand allows you to take the source for such a program and
66 DLLs and compile it into the native format of a x86 Unix or Linux
67 operating system. WineLib also allows you to partially compile the
68 program and DLLs into the native format. For example, if you use a DLL
69 from a vendor to provide some functions to your program and the vendor
70 does not give you source, then you can use the Windows version of the
71 DLL to provide the functions and compile the rest of your program in
72 the native form for your system. [1]
73
74 Windows compilers assume a different structure than standard
75 compilers. For example, standard compilers assume that the function
76 main() exists and is the entry point of the program. On the other
77 hand, windows compilers create a main() that issues an error message
78 that states that windows is required for executing the program and the
79 real entry point is the function WinMain(). As a result, WineLib
80 provides certain aids to generate code so that your program can be
81 compiled and run as written for windows. For example, WineLib
82 generates a main() to initialize the windows API, to load any
83 necessary DLLs and then call your WinMain(). Therefore, you need to
84 learn four basic operations to compile a windows program using
85 WineLib: compiling a simple program, compiling resources, compiling
86 libraries, and compiling MFC. These skills or operations are explained
87 in later sections of this HOWTO.
88
89 Before you start porting your windows code to WineLib, you need to
90 consider whether you are allowed to port your program to WineLib. As
91 you compile your program using WineLib, you will be combining software
92 from several sources and you need to ensure that the licenses for the
93 components are compatible. Hence, in the next section, we will examine
94 several legal issues.
95
96 II. Legal Issues
97
98 Disclaimer! I am not a lawyer. The purpose of this section is to make
99 you aware of potential legal problems. Be sure to read your licenses
100 and to consult your attorney.
101
102 During the compilation of your program, you will be combining code
103 from several sources: your code, WineLib code, code from your vendor's
104 DLLs (if any), and Microsoft MFC code (if used). As a result, you must
105 ensure that the licenses of all code sources are obeyed. What you are
106 allowed and not allowed to do can vary depending on how you compile
107 your program and if you will be distributing it. For example, if you
108 are releasing your code under the GPL, you cannot link your code to
109 MFC code because the GPL requires that you provide ALL sources to your
110 users. The MFC license forbids you from distributing the MFC source so
111 you can not comply with the GPL license except by not distributing you
112 program. On the other hand, if your code is released under the LGPL,
113 you cannot statically link your program to MFC and distribute it, but
114 you can dynamically link your LGPL code and MFC code and distribute
115 it.
116
117 Wine/WineLib is distributed under an X11-like license. It places few
118 restrictions on the use and distribution of Wine/WineLib code. I doubt
119 the Wine license will cause you any problems. On the other hand, MFC
120 is distributed under a very restrictive license and the restrictions
121 vary from version to version and between service packs.
122
123 If you plan on using MFC, there are three hurdles to legally using
124 MFC. The first hurdle is how to legally get MFC source code on your
125 computer. MFC source code comes as a part of Visual Studio. The
126 license for Visual Studio implies it is a single product that can not
127 be broken up into its components. The cleanest way to get MFC on you
128 system is to use a dual boot Linux box with the windows partition
129 visible to the Linux OS. Boot into windows and install Visual
130 Studio. Since Visual Studio is installed on the computer, you have not
131 broken it into its components. There may be other solutions, but I
132 think this is the easiest.
133
134 FIXME: quote relevant sections of EULA in above paragraph.
135
136 The second hurdle for MFC is the legality of compiling MFC on a
137 non-Microsoft operating system. This varies with the version of MFC.
138
139 MFC license from Visual Studio 6.0:
140
141     1.1 General License Grant. Microsoft grants to you as an
142     individual, a personal, nonexclusive license to make and use
143     copies of the SOFTWARE PRODUCT for the sole purposes of designing,
144     developing, and testing your software product(s) that are designed
145     to operate in conjunction with any Microsoft operating system
146     product. [Other unrelated stuff deleted.]
147
148 So it appears you cannot compile MFC for WineLib using this
149 license. On the other hand, Visual Studio 6.0 service pack 3 (Visual
150 Studio 5.0 is similar):
151
152     1.1 General License Grant. Microsoft grants to you as an
153     individual, a personal, nonexclusive license to make and use
154     copies of the SOFTWARE PRODUCT for the purpose of designing,
155     developing, and testing your software product(s). [Other unrelated
156     stuff deleted]
157
158 So it appears you can compile MFC for WineLib using this license.
159
160 The third hurdle is your legal right to distribute an MFC
161 library. Check the relevant section of the license on redistributables
162 and your redistribution rights. As I read the license, you only have
163 the right to distribute binaries of the MFC library if it has no debug
164 information and if you distribute it with an application that provides
165 significant added functionality to the MFC library.
166
167 FIXME: quote relevant sections of EULA in above paragraph.
168
169 Once you have examined the licenses for all of the sources used in
170 compiling your program and have decided you can legally compile you
171 program using WineLib, you should probably experiment with your
172 program running under Wine to determine how much work will be involved
173 in the port. The next section will give advice on estimating the
174 amount of work required for porting your program to WineLib.
175
176 III. How Much Work?
177
178 Wine and WineLib use the same functions to implement the windows API;
179 hence, if your program correctly runs under Wine, it should run under
180 WineLib. However, Wine/WineLib is incomplete; you may have trouble
181 running your program under Wine. Many people have successfully run many
182 programs under Wine, so there is a good chance you will have no
183 trouble.
184
185 Wine executes the binary program that was compiled for a windows
186 operating system. There are differences between the windows operating
187 system and Unix/Linux operating systems. For example, in Windows 95
188 and Windows 98, the program has direct access to the hardware. A copy
189 protection program that you purchased for your windows executable may
190 use direct hardware access to write data to the disk. Hence, you may
191 need to disable the copy protection in order to test your executable
192 under Wine.
193
194 As a specific example, CrypKey is a copy protection program we use at
195 Lumin Software. Our program does not execute under Wine with the copy
196 protection enabled. We disabled the copy protection, recompiled the
197 windows executable, and our program works fine. CrypKey also works for
198 Windows NT where it creates a service. Using Wine with the --winver
199 nt40 option "almost" gets the our program working with copy
200 protection. At a later date, we intend to either implement the system
201 calls in Wine that are missing for CrypKey or to use another copy
202 protection program that does work under Linux.
203
204 During the execution of your program, Wine prints error messages to
205 standard error. These error messages include "stubs", which are
206 windows API functions that have not been completely
207 implemented. Depending on the the system call, these could be harmless
208 or crash your program. Most of the common windows API functions have
209 already been implemented, so you should have no missing API functions
210 or only a few missing functions. If you intend to continue with the
211 port to WineLib, you will need to implement these API
212 functions. After running your program for a while, you should have a
213 good feel for the number of windows API functions that you need to
214 implement. 
215
216 FIXME: give info on Wine command line options to control error
217 messages. 
218
219 It is not necessary for you to implement the entire documented
220 behavior of an API function in order to get your program to work. For
221 example, many API functions have pointer parameters that are NULL in
222 the common cases. If you always call the function with a NULL pointer
223 for the default behavior, you can save yourself some effort by
224 implementing a function that only works for the NULL pointer
225 parameter. If you do this, make sure you test if the parameter is
226 non-null and issue a warning for the non-null case. Also document in
227 the source that the API function is incomplete.
228
229 FIXME: give info on the FIXME (macro/function?) for partially
230 implemented API functions.
231
232 Once you have implemented an API function, submit the change back to
233 the Wine project so the next person to need the same function does not
234 need to repeat your work. Remember, someone else wrote all of the
235 other API functions that you are using, so you are benefiting from
236 their work. Let other people benefit from your work as well. If you
237 work for a company, you may need your company's permission to "give
238 away" your work.
239
240 IV. File Format Conversion
241
242 Before you can compile your program, you must deal with one major
243 difference between Windows and WineLib. Window sources are in DOS
244 format with carriage return / line feed at the end of each line of
245 text while WineLib files are in Unix format with only line feed at the
246 end of each line of text. Before you compile your sources, you will
247 need to convert you DOS format sources to Unix format. There are
248 several tools such as dos2unix and tr that are available to convert
249 the format.
250
251 FIXME: explain about line continuation in macros with CR/LF lines.
252
253 FIXME: get more info on dos2unix, tr, and all other such tools and
254 give example commands. Until I do [3] is a good source.
255
256 FIXME: is CR/LF conversion necessary for gcc 2.95 ?
257
258 V. Compiling A Simple Win32 Program 
259
260 Wine and WineLib are written in C as is the MS Win32 API; thus, if
261 have a program that calls only the Win32 API directly, you can compile
262 the program using a C compiler and link it with some of the WineLib
263 libraries. There are several simple examples of WineLib programs in
264 the directory libtest/ in the Wine source tree. We shall examine one
265 of these to show you how to compile a WineLib program.
266
267 The example we shall examine is hello2. If you examine hello2.c, you
268 will see it is a windows program that pops up a message box that says
269 "Hello, hello!". It can be compiled and run using a windows compiler
270 just like any other windows program. However, it can not be compiled
271 and run with a non-windows compiler. As mentioned previously, windows
272 programs have an entry point called WinMain(), while non-windows
273 compilers use an entry point of main(). Hence, we need some "glue" to
274 glue the main() entry point to the WinMain() in the windows program.
275
276 In WineLib, the glue is provided by the spec file. Spec files are used
277 in several places in Wine and WineLib to provide glue between windows
278 code and code for non-windows compilers. WineLib provides a tool
279 called winebuild in the tools/winebuild directory that converts a spec file
280 into a C file that can be compiled and linked with the windows source
281 files. If you examine hello2.spec, you will see the following:
282
283 name    hello2
284 mode    guiexe
285 type    win32
286 init    WinMain
287
288 Name is the name of the application. Mode is the type of "glue" that
289 winebuild needs to create. Possible modes are 'dll' for a library,
290 'cuiexe' for a console application, and 'guiexe' for a regular
291 graphical application. Type is the type of API, either win32 or
292 win16. Win16 is supported only in Wine, not WineLib, so you should use
293 win32. Init is the function to call for initialization: in this case,
294 WinMain.
295
296 During compilation of the hello2 executable, the following command is
297 executed. 
298
299 ../tools/winebuild/winebuild -fPIC -o hello2.spec.c -spec hello2.spec
300
301 The program winebuild will generate the output file hello2.spec.c (option
302 -o hello2.spec.c) from the spec file hello2.spec (option -spec
303 hello2.spec). The output file contains some assembly directives and
304 these directives are position independent code (option -fPIC). The
305 winebuild program is used in several places in Wine as well as WineLib;
306 however, only the -spec option will be used in WineLib. The output
307 file hello2.spec.c contains main() and the glue code to initialize
308 WineLib and call WinMain().
309
310 FIXME: for WineLib users -- is there ever a need to not specify -fPIC?
311
312 Now the compilation of hello2 can proceed as any other compilation for
313 a program.
314
315 gcc -c -I. -I. -I../include -I../include -g -O2 -Wall  -D_REENTRANT \
316 -I/usr/X11R6/include -o hello2.o hello2.c 
317
318 FIXME: -D_REENTRANT why?
319 FIXME: explain compiler options
320
321 to compile the window program itself and 
322
323 gcc -c -I. -I. -I../include -I../include -g -O2 -Wall -D_REENTRANT \
324 -I/usr/X11R6/include -o hello2.spec.o hello2.spec.c
325
326 to compile the main() and the glue code. Finally,
327
328 gcc -o hello2 hello2.o hello2.spec.o -L../dlls  -L.. -lwine -lncurses
329 -lm  -lutil -ldl                                 
330
331 FIXME: explain linker options
332
333 will link the files into an executable. All of the steps are automated
334 with the makefile, so "make hello2" will execute all of the steps for
335 you. 
336
337 Thus, you now have the basics of compiling a simple windows
338 program. There are two more things to learn for compiling more complex
339 windows programs: windows resources and DLL dependencies. Window
340 resources are described in the next section. DLL dependencies are
341 handled by linker magic with windows compilers. Thus, you will need to
342 provide information about which DLLs your program depends. This
343 information is given in the spec file. For example, if our hello2
344 program had a .wav file that it played, it would need the multi-media
345 DLL winmm. Our spec file would then be
346
347 name    hello2
348 mode    guiexe
349 type    win32
350 init    WinMain
351 import  winmm
352
353 If you need to list multiple DLLs, then the import specification can
354 appear multiple times.
355
356 FIXME: can multiple libraries appear on one import line?
357
358 VI. Compiling A Win32 Program With Resources
359
360 FIXME: to be continued.
361 Describe wrc.
362 Go through hello world example 3.
363
364 VII. DLLs
365     A. Native DLL.
366     B. so DLL.
367     C. elfdll.
368     D. resource DLL
369
370 FIXME: to be continued.
371 QUESTION: what are so DLL and elfdll. I think I have been doing so
372 DLL. 
373
374 Go over an example similar to edrlib in Petzold.
375
376 VIII. How to use MFC
377     A. Using a native MFC DLL
378     B. Compiling MFC
379
380 FIXME: to be continued.
381
382 =====================================================================
383 References
384
385 Until this HOWTO is complete, I will document who gives me what
386 information. 
387
388 Reference [1] 
389 From: Patrik Stridvall <ps@leissner.se>
390 To: "'wilbur.dale@lumin.nl'" <wilbur.dale@lumin.nl>,
391 Date:   Mon, 5 Jun 2000 14:25:22 +0200 
392
393 First of all WineLib suppport for Win16 has been discontinued
394 for quite some time, because:
395
396 1. It is difficult for us to support and it is impossible
397    to do so prefectly without special compiler support,
398    because of memory layout issues. For example Win16 int
399    is 16-bit and data is aligned 16-bit.
400 2. It is in almost all cases easier to port a
401    Win16 application to Win32.
402
403 A minor detail, I personally would prefer that Wine and WineLib
404 was always used in the uppercase W and uppercase L variant,
405 instead of, as in your document, sometime one variant, sometimes
406 another.
407
408 Reference [2] 
409 From: michael cardenas <mbc@deneba.com>
410 To: wilbur.dale@lumin.nl
411 Date:   Mon, 5 Jun 2000 13:19:34 -0400
412
413 a few things you should mention...
414
415 - you can compile resources as a dll under windows and then load the dll
416 with wine. That's what we do for canvas. This is probably not ideal, but
417 most of my problems porting were in the code. We very seldomly have to
418 change the resources for the porting process. But wrc does work for most
419 cases...
420
421 - the error messages can be turned off or turned up with options to
422 configure like --enable-trace-msgs=wireoff or --enable-trace-msgs=wireon .
423 Take a look at configure.
424
425 - you probably want to compile your WineLib with --disable-debugger, at
426 least for the release version of your app.
427
428 Reference [3] 
429 http://fgouget/wine/winelib-en.shtml
430
431 =====================================================================
432
433 The information included here is from various Wine-devel posting and
434 private e-mails. I am including them so that any one starting on MFC
435 will have some documentation. Glean what you can and good luck.
436
437 Before I write more detailed info on compiling MFC I have three
438 questions. The info I have mentions three problems:
439
440     1. Wine header files---what is the status of this? Do changes need
441     to be made in the headers and if so, do I submit the changes back
442     into Wine cvs? Do the changes need #ifdef for C vs. C++
443     compilation? 
444
445     2. DOS format files <CR/LF> and no case distinction in
446     filenames. Do the extensions Corel made to gcc 2.95 handle this?
447     If so, how?
448
449     3. Microsoft extensions to the C++ syntax. Do the extensions Corel
450     made to gcc 2.95 handle this? If so, how?
451
452 If you have info that needs to be added, send me email at
453 <wilbur.dale@lumin.nl> and I will add it.
454
455 =====================================================================
456
457 THANKS
458
459 Most of the information in this file came from postings on
460 <Wine-devel@Winehq.com> and from private e-mails. The following people
461 contributed information for this document and I thank them for their
462 time and effort in answering my questions. I also want to thank them
463 for encouraging me to attack the MFC problem. 
464
465 CONTRIBUTERS:
466
467     Damyan Ognyanoff <Damyan@rocketmail.com>
468     Gavriel State <gav@magmacom.com>
469     Ian Schmidt <ischmidt@cfl.rr.com>
470     Jeremy White <jwhite@codeweavers.com>
471
472
473 From: Ian Schmidt <ischmidt@cfl.rr.com>
474 Subject: Re: WineLib and MFC
475
476 "Wilbur N. Dale" wrote:
477
478 > What is the status of MFC under WineLib?
479
480 I don't know precisely. Corel has done more MFC work than anyone (all
481 of their applications which they are porting are MFC-based), and
482 reportedly they have MFC itself compiled. I was just trying to get a
483 moderately simple MFC-using app to compile, with moderate success
484 (there are still some problems with MFC's headers after my patch, but
485 at least they don't appear to be Wine's fault :) I did not try to
486 compile MFC itself.
487
488 > Which versions of MFC, if any?
489
490 I have no idea what version Corel uses. As noted in my patch, I was
491 fiddling with the headers for MFC 6 (from Visual C++ 6.0 Service Pack
492 3). Most of the stuff my patch addressed was for newer IE 5-related
493 features, so I'd guess MFC 5 (VC++ 5.0) is likely what they used.
494
495 > Is there any documentation on how to compile MFC for WineLib?  If so
496 > where?
497
498 Not that I know of.
499
500 > I have started to compile programs using WineLib (hello.c last
501 > Sunday) and expect to be ready to start compiling MFC in a couple of
502 > weeks. If documentation is not available on compiling MFC, I am
503 > willing to write it.
504
505 Documentation would be a Good Thing, as WineLib in general is grossly
506 underdocumented right now. Here's a few tips I discovered to get you
507 started:
508
509 - First off, run all the MFC headers (and source too if you try it)
510 through a utility to strip out the DOS carriage returns. They cause
511 havoc with GCC when it sees one after a line that ends with a \ (and
512 MFC has many macros in it's headers that meet that description). If
513 you don't have one, do a Google search on "fromdos" and you should
514 locate some source (or it's fairly easy to make your own).
515
516 - Use GCC 2.95.2, and the -fpermissive flag to make it less picky.
517 2.95.2 has some VC++-compatibility features that Corel paid for, and I
518 believe more are forthcoming in future GCCs.
519
520 - Use -I to add whereever you have the MFC headers at to your include
521 path, as MFC apps typically use #include <> to access them rather than
522 "".
523
524 - Be prepared to have to rename and/or symlink headers, unless you
525 compile on a case-insensitive filesystem :)
526
527 - When you make install Wine it seems not to include all it's headers
528 in /usr/local/include/Wine. To have any chance at getting MFC going
529 you'll want to use -I to add the include/ directory from the Wine
530 source tarball to the path so it can grab everything.
531
532 Sorry I can't help you more, but good luck!
533
534 -Ian Schmidt
535 ischmidt@cfl.rr.com
536
537
538 From: Jeremy White <jwhite@codeweavers.com>
539 Subject: Re: RFC: Wine 1.0
540
541 "Wilbur N. Dale" wrote:
542 > > Further, we have successfully built MFC after making only
543 > > a modest set of changes to it, even with older
544 > > versions of g++.
545
546 > Lumin Software is about to use WineLib to port a window program to linux. A
547 > couple of years ago we thought we had to make a modification to MFC for one
548 > of our projects and we had problems getting MFC to compile under MS Visual C++.
549 > After much wailing and gnashing of teeth, we gave up and did things another
550 > way. After this bad experience, we were wondering --- approximately how many
551 > man-hours did you spend compiling and changing MFC ?
552
553     Urk. I misspoke. None of the developers here that I thought
554 had working versions of MFC with Wine have working versions any
555 longer. So, it may be a bit trickier than I led you to believe.
556
557     We have it working pretty reliably with TWine, but not 
558 quite so cleanly (yet) with Wine. However, it really shouldn't
559 be too difficult, and this is what I can remember of the process:
560
561         1. If you use a very modern version of gcc (2.95.2 or higher),
562             I believe you will need to add the -relaxed flag to
563             have any hope of compiling.
564
565         2. If you use an earlier version of gcc, you will need to
566             adjust the many anonymous structs/unions that MFC supplies.
567             We prefer this approach, because requiring very
568             modern gcc implementations seems harsh to us.
569
570         3. You will need to adjust for the many type differences
571             between MFC intrinsic types and the types supplied by Wine.
572             For example, I believe that MFC expects a HANDLE to
573             be compatible with certain scalar types, (and it is
574             under Windows/VC, but is not with Wine/gcc).
575
576         4. The key procedure:  add many -DNO_XXX flags to the
577             makefile. If you start with Microsofts make file
578             for MFC, convert it into a Wine makefile, and then turn
579             on many of the flags they list there (of the form -DNO_XXX),
580             your life will get much easier. Once you get it working
581             with a few -DNO_XXX flags, you can go back and add them
582             back in.
583
584         5. The best resource:  you need someone who knows C++ very,
585             very well. You occassionaly run into very obscure C++
586             problems where MS has extended the C++ standard and
587             gcc has not. It really helps to have a guru on hand
588             when you hit those.
589
590
591 I hope this helps. Sorry for the earlier deceptive post.
592
593 Jeremy
594
595 From: Gavriel State <gav@magmacom.com>
596 Subject: Re: MFC questions
597
598 "Wilbur N. Dale" wrote:
599
600 > 1. Compile MFC. Several years ago we (Lumin Software) tried to
601 > compile MFC.  The attempt failed and we found another way to do what
602 > we wanted. MS documentation states that compiling MFC was
603 > deliberately made difficult.  Considering my experience with stuff
604 > they call "easy" I am not looking forward to compiling MFC. We are
605 > currently using Visual Studio 5 for windows development.
606
607 At Corel, we had MFC compiled and running sample apps in WineLib in
608 late 1998. It's mostly a question of the Wine headers, which weren't
609 originally up to snuff. We did quite a bit of work on them, and most
610 of those changes have been contributed back to WineHQ, so it should be
611 pretty easy now. The other thing that was a big deal was getting the
612 startup code working properly - since MFC needs to initialize static
613 data *after* WineLib gets initialized. I believe that that issue has
614 been addressed now on the WineHQ side with some of the work done on
615 the .spec file tools recently.
616
617 -Gav
618
619 -- 
620 Gavriel State
621 CEO
622 TransGaming Technologies Inc.
623 gav@transgaming.com
624
625 From: Jeremy White <jwhite@codeweavers.com>
626 Subject: Re: MFC questions
627
628 "Wilbur N. Dale" wrote:
629 [snip]
630 > 1. Compile MFC. Several years ago we (Lumin Software) tried to
631 > compile MFC.  The attempt failed and we found another way to do what
632 > we wanted. MS documentation states that compiling MFC was
633 > deliberately made difficult.  Considering my experience with stuff
634 > they call "easy" I am not looking forward to compiling MFC. We are
635 > currently using Visual Studio 5 for windows development.
636
637 Wilbur, I personally think that this is the 'right' approach, although
638 approach #2 may prove faster.
639
640 Despite your previous experience, and despite my earlier incorrect
641 statements, I think that this is simpler than you fear. It's one of
642 those tasks that's darkest before the storm - you spend all of your
643 energy getting all the include files to work. Once you have *one*
644 object file, the rest go much more quickly (alright, getting it to
645 link is also a hairball of a job, but it's tractable <g>).
646
647 If you're not in a hurry, getting MFC to compile, and having a
648 documented procedure for compiling it is on our agenda for the
649 relatively near future (see the Wine 1.0 task list).
650
651 Jer
652
653 p.s. Stick with Visi C++ 5. IMHO its MFC license is cleaner than that
654 of VC 6.
655
656 From: Gavriel State <gav@magmacom.com>
657 Subject: The MSVC++ 6.0 license
658
659 Jeremy White wrote:
660 > p.s. Stick with Visi C++ 5. IMHO its MFC license is cleaner than that
661 > of VC 6.
662
663 Actually, I just picked up a copy of MSVC 6.0 and it appears that they
664 changed the license between the original release and the Service Pack
665 3 release - they removed the bit in section 1.1 about requiring that
666 you be developing your software product only for use with a Microsoft
667 OS.  In any case, even the original license explicitly says that the
668 MFC redistribution rights are *in addition* to the usage rights in
669 section 1.1.
670
671 The relevant portion of the original EULA:
672
673  1.1    General License Grant. Microsoft grants to you as an individual, a
674  personal, nonexclusive license to make and use copies of the SOFTWARE 
675  PRODUCT for the sole purposes of designing, developing, and testing your
676  software product(s) that are designed to operate in conjunction with 
677  any Microsoft operating system product. [Other unrelated stuff deleted]
678
679 >From the SP3 EULA:
680
681  3.     Section 1.1 of the EULA is deleted in its entirety and replaced 
682  with the following:
683
684  1.1    General License Grant. Microsoft grants to you as an individual, a 
685  personal, nonexclusive license to make and use copies of the SOFTWARE 
686  PRODUCT for the purpose of designing, developing, and testing your 
687  software product(s). [Other unrelated stuff deleted]
688
689 Disclaimer - I am not a lawyer, but I've spent lots of time with them 
690 investigating software licenses.
691
692  -Gav
693
694 -- 
695 Gavriel State
696 CEO
697 TransGaming Technologies Inc.
698 gav@transgaming.com
699
700 From: Damyan Ognyanoff <Damyan@rocketmail.com>
701 Subject: Need a hint
702
703 Hi,
704
705 I manage to build mfc42 as .so library and a application using it (as
706 a .so library too). I execute it using simple loader which is linked
707 to Wine and I load my application in it's WinMain routine. The
708 problem is how clearly to unload mfc and my application (to invoke
709 mfc's destructors before loader is terminated) All is fine except that
710 there is a "zombi" reference to code in shared library which is
711 invoked in Wine code and generate GPF. debugger stops somewhere in
712 aplication's InitInstance !!! - and the stack is broken so I can't
713 catch where exactly the problem is. Any hints are welcome. I'm using
714 Wine-2000517 shapshot downloaded form Wine.datapary.no 
715
716 TNX.
717
718 Damyan
719 p.s.
720 If any of You is interested in details I can share my
721 experience.
722
723
724 From: Damyan Ognyanoff <Damyan@rocketmail.com>
725 Subject: Re: Wine MFC info request
726
727 hi,
728 my MFC is from VC6.0 with SP3
729 MFC Bulid: (form  afxbld_.h)
730     #define _MFC_BUILD 8447
731     #define _MFC_USER_BUILD "8447"
732     #define _MFC_RBLD 0
733 mfcdll.rc
734     FILEVERSION       6,0,_MFC_BUILD,_MFC_RBLD
735     PRODUCTVERSION    6,0,0,0
736
737 Hints:
738     1. Wine include files
739
740 In some of them you will find error about '__attribute__' all kinds of
741 similar errors can be fixed using proper typedefs first example :
742
743 typedef BOOL (CALLBACK *DLGPROC)(HWND,UINT,WPARAM,LPARAM);
744
745 must be converted to
746
747 typedef BOOL CALLBACK (*DLGPROC)(HWND,UINT,WPARAM,LPARAM);
748
749 and the second kind is something like
750
751 TYPE* WINAPI SomeFunction(HWND param1,UINT param2);
752
753 The problem here is a TYPE* or TYPE& (in some of mfc files) the
754 workaround is to declare a type before:
755
756 typedef TYPE* TYPEPtr; 
757
758 or
759
760 typedef TYPE& TYPERef;
761
762 and declaration will look like:
763
764 TYPEPtr WINAPI SomeFunction(HWND param1,UINT param2);
765
766 note: don't miss a 'struct' when you define struct type pointers. I
767 miss it and get a lot of problems compiling MFC:
768
769 >>
770 struct _TEB;
771 typedef !!!struct!!! _TEB* P_TEB;
772 extern inline P_TEB WINAPI NtCurrentTeb(void);
773 <<
774
775 Those conversions are semanticaly the same as above but g++ compile
776 them and generate proper code to invoke __stdcall kind of functions
777
778 in some of Wine/obj_XXX.h files: Wine/obj_base.h - there are a lot of
779 defines's that are used to declare a COM interfaces
780
781 #define ICOM_METHOD(ret,xfn) \
782      public: virtual ret (CALLBACK xfn)(void) = 0;
783
784 will be (for all of them that are related to C++ (watch #ifdef's
785 carefully)):
786
787 #define ICOM_METHOD(ret,xfn) \
788      public: virtual ret CALLBACK (xfn)(void) = 0;
789
790 and the second tip is an error when compiler stops on line like:
791  
792    ICOM_DEFINE(ISomeInterfase,IUnknown)
793
794 watch method declarations above to find something like:
795
796 ICOM_METHOD1(TYPE*,MethodName, DWORD,dwParam)
797
798 and replace TYPE* with proper TYPEPtr type. In many cases You will see
799 void* which can be replaced simply by LPVOID.
800
801 qthere are several errors related to anonymous structs and unions but
802 they can be avoided with proper - #ifdef __cplusplus
803
804 This is all about Wine headers I think. If you find something that I
805 miss type a line of mail to me.
806
807 2. MFC
808 The rules are the same with some new issues:
809
810 virtual BOOL Method1(int param1, BOOL (CALLBACK *param2)
811 (HWND,UINT,WPARAM,LPARAM));
812
813 don't compile. I remove a function pointer declaration
814 outside method:
815
816 typedef BOOL CALLBACK
817 (*param2Type)(HWND,UINT,WPARAM,LPARAM);
818
819 virtual BOOL Method1(int param1, param2Type param2);
820
821 I didn't apply this technique to a operator new
822 definitions:
823
824         void* AFXAPI operator new(size_t nSize);
825
826 so i remove AFXAPI from these declarations:
827
828 I got some missed #defines from commctrl.h and I added
829 them form VC6.0 include.
830
831 these are my defines form Makefile which I used to
832 compile MFC
833
834 -DTWINE_NO_CMONIKER \ -- this is related to exclude
835 CMonikerFile 
836 -D__urlmon_h__ \ -- Wine didn't have URL interfaces 
837 -D_AFX_NO_OLEDB_SUPPORT \
838 -D_WIN32  \
839 -DNOWIN98  \ -- this is used to exclude all
840 unimplemented classes from commctrl 
841 -D_AFX_PACKING \
842 -D_AFX_NO_DHTML_SUPPORT \
843 -D_AFX_NO_SOCKET_SUPPORT \
844 -D_AFX_NO_SYNC_SUPPORT \
845 -D_AFX_NO_OCX_SUPPORT  \
846 -D_AFX_PORTABLE \
847 -D_AFX_OLD_EXCEPTIONS \
848 -D_AFX_NO_SOCKET_SUPPORT \
849 -D_AFX_NO_DEBUG_CRT \
850 -D_AFX_NO_DAO_SUPPORT \
851 -D_AFX_NO_OCC_SUPPORT \
852 -D_AFX_NO_INET_SUPPORT \
853 -D_AFX_NO_RICHEDIT_SUPPORT  \
854 -D_X86_ \
855 -DLONGHANDLES
856
857 may be you will try to enable some of features of mfc I tested only
858 -D_AFX_NO_OCC_SUPPORT but got missing interfaces from Wine
859
860 in file afxcom_.h
861 - _CIP<_Interface, _IID>::~_CIP<_Interface, _IID>()
862 + _CIP<_Interface, _IID>::~_CIP()
863
864 in file afxtempl.h
865 -       BOOL Lookup(BASE_CLASS::BASE_ARG_KEY key,
866 VALUE& rValue) const
867 -               { return BASE_CLASS::Lookup(key,
868 (BASE_CLASS::BASE_VALUE&)rValue); }
869 +       BOOL Lookup(typename BASE_CLASS::BASE_ARG_KEY
870 key, VALUE& rValue) const
871 +               { return BASE_CLASS::Lookup(key,
872 (typename BASE_CLASS::BASE_VALUE&)rValue); }
873
874 and all releated errors can be fixed in this way.
875
876 3. spec file
877     name        mfc42
878     type        win32
879     rsrc        mfc42
880
881     10 stdcall WinMain(long long ptr long) WinMain
882
883 4. linking 
884     use -rdynamic wnen link libmfc.so to get ARGV and
885 ARGC from loader
886     
887 5. I didn'n build a extension dll with Wine but I suspect that there
888 will be some problems related to a chaining Runtime classes form MFC
889 to a new dll
890
891 6. build your app as a MODULE too.
892
893 7. make a loader and in it's _WinMain:
894 ... includes are here
895 iint PASCAL (*winMain)(HINSTANCE,HINSTANCE,LPSTR,int) =
896 0;
897 my app uses these to manage filenames
898 VOID __cdecl (*_splitpath1)(LPCSTR path, LPSTR drive,
899 LPSTR directory, LPSTR filename, LPSTR extension ) =
900 NULL;
901 VOID __cdecl _splitpath(LPCSTR path, LPSTR drive,
902 LPSTR directory, LPSTR filename, LPSTR extension )
903 {
904     if (_splitpath1)
905         _splitpath1(path, drive, directory, filename,
906 extension );
907 }
908 VOID __cdecl (*_makepath1)(LPSTR path, LPCSTR drive,
909 LPCSTR directory, LPCSTR filename, LPCSTR extension )
910 = NULL;
911 VOID __cdecl _makepath(LPSTR path, LPCSTR drive,
912 LPCSTR directory, LPCSTR filename, LPCSTR extension )
913 {
914     if (_makepath1)
915         _makepath1(path, drive, directory, filename,
916 extension);
917 }
918 int PASCAL _WinMain(HINSTANCE h,HINSTANCE h1,LPSTR
919 lpszCmdParam,int c)
920 {
921   HINSTANCE hInstance,hins,hlib,htst,hform,himag,hexe;
922         int retv;
923
924         hins = LoadLibrary("CRTDLL.DLL");
925         _splitpath1 = GetProcAddress(hins,
926 "_splitpath");
927         _makepath1 = GetProcAddress(hins,
928 "_makepath");
929         hins = LoadLibrary("COMCTL32.DLL");
930         hins = LoadLibrary("COMDLG32.DLL");
931
932
933         hins = dlopen("libmfc42.so",2);
934         hlib = LoadLibrary("mfc42");
935         himag = dlopen("libmxformatslib.so",2);
936         hform = LoadLibrary("mxformatslib");
937         hexe = dlopen("libmxpaint.so",2);
938         htst = LoadLibrary("mxpaint");
939
940         winMain = GetProcAddress(hlib, "WinMain");
941         if (winMain)
942         {
943           retv = winMain (htst,    // note the > htst
944 < HERE
945                   0,            
946                   lpszCmdParam, 
947                   SW_NORMAL);   
948         }
949     FreeLibrary(htst);
950     FreeLibrary(hform);
951     FreeLibrary(hlib);
952     dlclose(hexe);
953     dlclose(himag);
954     dlclose(hins);
955     return retv;
956 }
957 the spec for loader is:
958 name    c10
959 mode    guiexe
960 type    win32
961 init    _WinMain
962
963 please find attached a Makefile which i use to build
964 MFC
965
966 Regards 
967 Damyan.
968
969  LocalWords:  WineLib HOWTO Jun vs DLLs DLL MFC NT FIXME CrypKey Kenonic API TM
970  LocalWords:  WinMain GPL LGPL EULA winver nt dos unix tr CR LF gcc libtest dll
971  LocalWords:  guiexe init cuiexe pic lwine lncurses lm lutil ldl wav winmm wrc
972  LocalWords:  elfdll edrlib Petzold Patrik Stridvall int michael cardenas msgs
973  LocalWords:  wireoff msgs wireon app devel cvs ifdef Corel Damyan Ognyanoff IE
974  LocalWords:  Gavriel MFC's Wine's VC underdocumented Google fromdos GCCs apps
975  LocalWords:  fpermissive whereever symlink filesystem tarball RFC linux Urk SP
976  LocalWords:  misspoke TWine structs DNO XXX Microsofts occassionaly WineHQ Gav
977  LocalWords:  TransGaming alright hairball Jer Visi IMHO MSVC nonexclusive mfc
978  LocalWords:  mfc's destructors zombi GPF aplication's InitInstance shapshot rc
979  LocalWords:  TNX Bulid afxbld RBLD mfcdll FILEVERSION PRODUCTVERSION BOOL HWND
980  LocalWords:  CALLBACK DLGPROC UINT WPARAM LPARAM WINAPI SomeFunction param TEB
981  LocalWords:  param TYPEPtr TYPERef struct struct NtCurrentTeb semanticaly obj
982  LocalWords:  stdcall obj defines's COM ICOM ret xfn ifdef's ISomeInterfase URL
983  LocalWords:  IUnknown MethodName DWORD dwParam LPVOID qthere cplusplus AFXAPI
984  LocalWords:  nSize commctrl DTWINE CMONIKER CMonikerFile urlmon AFX OLEDB SYNC
985  LocalWords:  DNOWIN DHTML OCX DAO OCC INET RICHEDIT DLONGHANDLES afxcom CIP SW
986  LocalWords:  IID CIP IID afxtempl ARG rValue const typename releated rsrc ptr
987  LocalWords:  rdynamic wnen libmfc ARGV ARGC didn'n extention iint winMain hins
988  LocalWords:  HINSTANCE HINSTANCE LPSTR cdecl splitpath LPCSTR makepath hlib
989  LocalWords:  lpszCmdParam hInstance htst hform himag hexe retv LoadLibrary
990  LocalWords:  CRTDLL GetProcAddress COMCTL COMDLG dlopen libmxformatslib
991  LocalWords:  mxformatslib libmxpaint mxpaint FreeLibrary dlclose