Started implementation of the functions GetDefaultCommConfigA/W.
[wine.git] / documentation / HOWTO-winelib
blob59f32794ba1ed9ec53c4a73ee309411844886ae4
1 WineLib HOWTO
2 Version 11-Jun-2000
4 AUTHOR: 
5 Wilbur Dale
6 Lumin Software BV
7 Zandheuvel 52 B
8 4901 HW Oosterhout (NB)
9 The Netherlands
11 wilbur.dale@lumin.nl
13 WARNING: This HOWTO is incomplete. I expect to add to it on a weekly
14 basis until it is complete.
16 =====================================================================
18 Table of Contents
20    I. Introduction: Wine vs. WineLib
22   II. Legal Issues
24  III. How Much Work?
26   IV. File Format Conversion
28    V. Compiling A Simple Win32 Program 
30   VI. Compiling A Win32 Program With Resources
32  VII. DLLs
33     A. Native DLL.
34     B. so DLL.
35     C. elfDLL.
36     D. resource DLL.
38 VIII. How to use MFC
39     A. Using a native MFC DLL
40     B. Compiling MFC
42 VIII. Trademarks
43 Windows 3.x, Windows 95, Windows 98, Windows NT are trademarks of
44 Microsoft Corporation. 
46 Unix is a trademark of ???? FIXME: who has the trademark this week?
48 CrypKey is a trademark of Kenonic Controls Ltd.
50 All other trademarks are the property of their respective owners.
52 =====================================================================
54 I. Introduction: Wine vs. WineLib
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]
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.
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.
96 II. Legal Issues
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.
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
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.
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.
134 FIXME: quote relevant sections of EULA in above paragraph.
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.
139 MFC license from Visual Studio 6.0:
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.]
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):
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]
158 So it appears you can compile MFC for WineLib using this license.
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.
167 FIXME: quote relevant sections of EULA in above paragraph.
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.
176 III. How Much Work?
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.
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.
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.
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. 
216 FIXME: give info on Wine command line options to control error
217 messages. 
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.
229 FIXME: give info on the FIXME (macro/function?) for partially
230 implemented API functions.
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.
240 IV. File Format Conversion
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.
251 FIXME: explain about line continuation in macros with CR/LF lines.
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.
256 FIXME: is CR/LF conversion necessary for gcc 2.95 ?
258 V. Compiling A Simple Win32 Program 
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.
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.
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 build in the tools/ directory that converts a spec file into a
280 C file that can be compiled and linked with the windows source
281 files. If you examine hello2.spec, you will see the following:
283 name    hello2
284 mode    guiexe
285 type    win32
286 init    WinMain
288 Name is the name of the application. Mode is the type of "glue" that
289 build 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.
296 FIXME: tools/build-spec.txt appears out of date. No "mode" is in the
297 documentation. 
299 During compilation of the hello2 executable, the following command is
300 executed. 
302 ../tools/build -pic -o hello2.spec.c -spec hello2.spec
304 The program build will generate the output file hello2.spec.c (option
305 -o hello2.spec.c) from the spec file hello2.spec (option -spec
306 hello2.spec). The output file contains some assembly directives and
307 these directives are position independent code (option -pic). The
308 build program is used in several places in Wine as well as WineLib;
309 however, only the -spec option will be used in WineLib. The output
310 file hello2.spec.c contains main() and the glue code to initialize
311 WineLib and call WinMain().
313 FIXME: for WineLib users -- is there ever a need to not specify -pic?
315 Now the compilation of hello2 can proceed as any other compilation for
316 a program.
318 gcc -c -I. -I. -I../include -I../include -g -O2 -Wall  -D_REENTRANT \
319 -I/usr/X11R6/include -o hello2.o hello2.c 
321 FIXME: -D_REENTRANT why?
322 FIXME: explain compiler options
324 to compile the window program itself and 
326 gcc -c -I. -I. -I../include -I../include -g -O2 -Wall -D_REENTRANT \
327 -I/usr/X11R6/include -o hello2.spec.o hello2.spec.c
329 to compile the main() and the glue code. Finally,
331 gcc -o hello2 hello2.o hello2.spec.o -L../dlls  -L.. -lwine -lncurses
332 -lm  -lutil -ldl                                 
334 FIXME: explain linker options
336 will link the files into an executable. All of the steps are automated
337 with the makefile, so "make hello2" will execute all of the steps for
338 you. 
340 Thus, you now have the basics of compiling a simple windows
341 program. There are two more things to learn for compiling more complex
342 windows programs: windows resources and DLL dependencies. Window
343 resources are described in the next section. DLL dependencies are
344 handled by linker magic with windows compilers. Thus, you will need to
345 provide information about which DLLs your program depends. This
346 information is given in the spec file. For example, if our hello2
347 program had a .wav file that it played, it would need the multi-media
348 DLL winmm. Our spec file would then be
350 name    hello2
351 mode    guiexe
352 type    win32
353 init    WinMain
354 import  winmm
356 If you need to list multiple DLLs, then the import specification can
357 appear multiple times.
359 FIXME: can multiple libraries appear on one import line?
361 VI. Compiling A Win32 Program With Resources
363 FIXME: to be continued.
364 Describe wrc.
365 Go through hello world example 3.
367 VII. DLLs
368     A. Native DLL.
369     B. so DLL.
370     C. elfdll.
371     D. resource DLL
373 FIXME: to be continued.
374 QUESTION: what are so DLL and elfdll. I think I have been doing so
375 DLL. 
377 Go over an example similar to edrlib in Petzold.
379 VIII. How to use MFC
380     A. Using a native MFC DLL
381     B. Compiling MFC
383 FIXME: to be continued.
385 =====================================================================
386 References
388 Until this HOWTO is complete, I will document who gives me what
389 information. 
391 Reference [1] 
392 From: Patrik Stridvall <ps@leissner.se>
393 To: "'wilbur.dale@lumin.nl'" <wilbur.dale@lumin.nl>,
394 Date:   Mon, 5 Jun 2000 14:25:22 +0200 
396 First of all WineLib suppport for Win16 has been discontinued
397 for quite some time, because:
399 1. It is difficult for us to support and it is impossible
400    to do so prefectly without special compiler support,
401    because of memory layout issues. For example Win16 int
402    is 16-bit and data is aligned 16-bit.
403 2. It is in almost all cases easier to port a
404    Win16 application to Win32.
406 A minor detail, I personally would prefer that Wine and WineLib
407 was always used in the uppercase W and uppercase L variant,
408 instead of, as in your document, sometime one variant, sometimes
409 another.
411 Reference [2] 
412 From: michael cardenas <mbc@deneba.com>
413 To: wilbur.dale@lumin.nl
414 Date:   Mon, 5 Jun 2000 13:19:34 -0400
416 a few things you should mention...
418 - you can compile resources as a dll under windows and then load the dll
419 with wine. That's what we do for canvas. This is probably not ideal, but
420 most of my problems porting were in the code. We very seldomly have to
421 change the resources for the porting process. But wrc does work for most
422 cases...
424 - the error messages can be turned off or turned up with options to
425 configure like --enable-trace-msgs=wireoff or --enable-trace-msgs=wireon .
426 Take a look at configure.
428 - you probably want to compile your WineLib with --disable-debugger, at
429 least for the release version of your app.
431 Reference [3] 
432 http://fgouget/wine/winelib-en.shtml
434 =====================================================================
436 The information included here is from various Wine-devel posting and
437 private e-mails. I am including them so that any one starting on MFC
438 will have some documentation. Glean what you can and good luck.
440 Before I write more detailed info on compiling MFC I have three
441 questions. The info I have mentions three problems:
443     1. Wine header files---what is the status of this? Do changes need
444     to be made in the headers and if so, do I submit the changes back
445     into Wine cvs? Do the changes need #ifdef for C vs. C++
446     compilation? 
448     2. DOS format files <CR/LF> and no case distinction in
449     filenames. Do the extensions Corel made to gcc 2.95 handle this?
450     If so, how?
452     3. Microsoft extensions to the C++ syntax. Do the extensions Corel
453     made to gcc 2.95 handle this? If so, how?
455 If you have info that needs to be added, send me email at
456 <wilbur.dale@lumin.nl> and I will add it.
458 =====================================================================
460 THANKS
462 Most of the information in this file came from postings on
463 <Wine-devel@Winehq.com> and from private e-mails. The following people
464 contributed information for this document and I thank them for their
465 time and effort in answering my questions. I also want to thank them
466 for encouraging me to attack the MFC problem. 
468 CONTRIBUTERS:
470     Damyan Ognyanoff <Damyan@rocketmail.com>
471     Gavriel State <gav@magmacom.com>
472     Ian Schmidt <ischmidt@cfl.rr.com>
473     Jeremy White <jwhite@codeweavers.com>
476 From: Ian Schmidt <ischmidt@cfl.rr.com>
477 Subject: Re: WineLib and MFC
479 "Wilbur N. Dale" wrote:
481 > What is the status of MFC under WineLib?
483 I don't know precisely. Corel has done more MFC work than anyone (all
484 of their applications which they are porting are MFC-based), and
485 reportedly they have MFC itself compiled. I was just trying to get a
486 moderately simple MFC-using app to compile, with moderate success
487 (there are still some problems with MFC's headers after my patch, but
488 at least they don't appear to be Wine's fault :) I did not try to
489 compile MFC itself.
491 > Which versions of MFC, if any?
493 I have no idea what version Corel uses. As noted in my patch, I was
494 fiddling with the headers for MFC 6 (from Visual C++ 6.0 Service Pack
495 3). Most of the stuff my patch addressed was for newer IE 5-related
496 features, so I'd guess MFC 5 (VC++ 5.0) is likely what they used.
498 > Is there any documentation on how to compile MFC for WineLib?  If so
499 > where?
501 Not that I know of.
503 > I have started to compile programs using WineLib (hello.c last
504 > Sunday) and expect to be ready to start compiling MFC in a couple of
505 > weeks. If documentation is not available on compiling MFC, I am
506 > willing to write it.
508 Documentation would be a Good Thing, as WineLib in general is grossly
509 underdocumented right now. Here's a few tips I discovered to get you
510 started:
512 - First off, run all the MFC headers (and source too if you try it)
513 through a utility to strip out the DOS carriage returns. They cause
514 havoc with GCC when it sees one after a line that ends with a \ (and
515 MFC has many macros in it's headers that meet that description). If
516 you don't have one, do a Google search on "fromdos" and you should
517 locate some source (or it's fairly easy to make your own).
519 - Use GCC 2.95.2, and the -fpermissive flag to make it less picky.
520 2.95.2 has some VC++-compatibility features that Corel paid for, and I
521 believe more are forthcoming in future GCCs.
523 - Use -I to add whereever you have the MFC headers at to your include
524 path, as MFC apps typically use #include <> to access them rather than
527 - Be prepared to have to rename and/or symlink headers, unless you
528 compile on a case-insensitive filesystem :)
530 - When you make install Wine it seems not to include all it's headers
531 in /usr/local/include/Wine. To have any chance at getting MFC going
532 you'll want to use -I to add the include/ directory from the Wine
533 source tarball to the path so it can grab everything.
535 Sorry I can't help you more, but good luck!
537 -Ian Schmidt
538 ischmidt@cfl.rr.com
541 From: Jeremy White <jwhite@codeweavers.com>
542 Subject: Re: RFC: Wine 1.0
544 "Wilbur N. Dale" wrote:
545 > > Further, we have successfully built MFC after making only
546 > > a modest set of changes to it, even with older
547 > > versions of g++.
549 > Lumin Software is about to use WineLib to port a window program to linux. A
550 > couple of years ago we thought we had to make a modification to MFC for one
551 > of our projects and we had problems getting MFC to compile under MS Visual C++.
552 > After much wailing and gnashing of teeth, we gave up and did things another
553 > way. After this bad experience, we were wondering --- approximately how many
554 > man-hours did you spend compiling and changing MFC ?
556     Urk. I misspoke. None of the developers here that I thought
557 had working versions of MFC with Wine have working versions any
558 longer. So, it may be a bit trickier than I led you to believe.
560     We have it working pretty reliably with TWine, but not 
561 quite so cleanly (yet) with Wine. However, it really shouldn't
562 be too difficult, and this is what I can remember of the process:
564         1. If you use a very modern version of gcc (2.95.2 or higher),
565             I believe you will need to add the -relaxed flag to
566             have any hope of compiling.
568         2. If you use an earlier version of gcc, you will need to
569             adjust the many anonymous structs/unions that MFC supplies.
570             We prefer this approach, because requiring very
571             modern gcc implementations seems harsh to us.
573         3. You will need to adjust for the many type differences
574             between MFC intrinsic types and the types supplied by Wine.
575             For example, I believe that MFC expects a HANDLE to
576             be compatible with certain scalar types, (and it is
577             under Windows/VC, but is not with Wine/gcc).
579         4. The key procedure:  add many -DNO_XXX flags to the
580             makefile. If you start with Microsofts make file
581             for MFC, convert it into a Wine makefile, and then turn
582             on many of the flags they list there (of the form -DNO_XXX),
583             your life will get much easier. Once you get it working
584             with a few -DNO_XXX flags, you can go back and add them
585             back in.
587         5. The best resource:  you need someone who knows C++ very,
588             very well. You occassionaly run into very obscure C++
589             problems where MS has extended the C++ standard and
590             gcc has not. It really helps to have a guru on hand
591             when you hit those.
594 I hope this helps. Sorry for the earlier deceptive post.
596 Jeremy
598 From: Gavriel State <gav@magmacom.com>
599 Subject: Re: MFC questions
601 "Wilbur N. Dale" wrote:
603 > 1. Compile MFC. Several years ago we (Lumin Software) tried to
604 > compile MFC.  The attempt failed and we found another way to do what
605 > we wanted. MS documentation states that compiling MFC was
606 > deliberately made difficult.  Considering my experience with stuff
607 > they call "easy" I am not looking forward to compiling MFC. We are
608 > currently using Visual Studio 5 for windows development.
610 At Corel, we had MFC compiled and running sample apps in WineLib in
611 late 1998. It's mostly a question of the Wine headers, which weren't
612 originally up to snuff. We did quite a bit of work on them, and most
613 of those changes have been contributed back to WineHQ, so it should be
614 pretty easy now. The other thing that was a big deal was getting the
615 startup code working properly - since MFC needs to initialize static
616 data *after* WineLib gets initialized. I believe that that issue has
617 been addressed now on the WineHQ side with some of the work done on
618 the .spec file tools recently.
620 -Gav
622 -- 
623 Gavriel State
625 TransGaming Technologies Inc.
626 gav@transgaming.com
628 From: Jeremy White <jwhite@codeweavers.com>
629 Subject: Re: MFC questions
631 "Wilbur N. Dale" wrote:
632 [snip]
633 > 1. Compile MFC. Several years ago we (Lumin Software) tried to
634 > compile MFC.  The attempt failed and we found another way to do what
635 > we wanted. MS documentation states that compiling MFC was
636 > deliberately made difficult.  Considering my experience with stuff
637 > they call "easy" I am not looking forward to compiling MFC. We are
638 > currently using Visual Studio 5 for windows development.
640 Wilbur, I personally think that this is the 'right' approach, although
641 approach #2 may prove faster.
643 Despite your previous experience, and despite my earlier incorrect
644 statements, I think that this is simpler than you fear. It's one of
645 those tasks that's darkest before the storm - you spend all of your
646 energy getting all the include files to work. Once you have *one*
647 object file, the rest go much more quickly (alright, getting it to
648 link is also a hairball of a job, but it's tractable <g>).
650 If you're not in a hurry, getting MFC to compile, and having a
651 documented procedure for compiling it is on our agenda for the
652 relatively near future (see the Wine 1.0 task list).
656 p.s. Stick with Visi C++ 5. IMHO its MFC license is cleaner than that
657 of VC 6.
659 From: Gavriel State <gav@magmacom.com>
660 Subject: The MSVC++ 6.0 license
662 Jeremy White wrote:
663 > p.s. Stick with Visi C++ 5. IMHO its MFC license is cleaner than that
664 > of VC 6.
666 Actually, I just picked up a copy of MSVC 6.0 and it appears that they
667 changed the license between the original release and the Service Pack
668 3 release - they removed the bit in section 1.1 about requiring that
669 you be developing your software product only for use with a Microsoft
670 OS.  In any case, even the original license explicitly says that the
671 MFC redistribution rights are *in addition* to the usage rights in
672 section 1.1.
674 The relevant portion of the original EULA:
676  1.1    General License Grant. Microsoft grants to you as an individual, a
677  personal, nonexclusive license to make and use copies of the SOFTWARE 
678  PRODUCT for the sole purposes of designing, developing, and testing your
679  software product(s) that are designed to operate in conjunction with 
680  any Microsoft operating system product. [Other unrelated stuff deleted]
682 >From the SP3 EULA:
684  3.     Section 1.1 of the EULA is deleted in its entirety and replaced 
685  with the following:
687  1.1    General License Grant. Microsoft grants to you as an individual, a 
688  personal, nonexclusive license to make and use copies of the SOFTWARE 
689  PRODUCT for the purpose of designing, developing, and testing your 
690  software product(s). [Other unrelated stuff deleted]
692 Disclaimer - I am not a lawyer, but I've spent lots of time with them 
693 investigating software licenses.
695  -Gav
697 -- 
698 Gavriel State
700 TransGaming Technologies Inc.
701 gav@transgaming.com
703 From: Damyan Ognyanoff <Damyan@rocketmail.com>
704 Subject: Need a hint
708 I manage to build mfc42 as .so library and a application using it (as
709 a .so library too). I execute it using simple loader which is linked
710 to Wine and I load my application in it's WinMain routine. The
711 problem is how clearly to unload mfc and my application (to invoke
712 mfc's destructors before loader is terminated) All is fine except that
713 there is a "zombi" reference to code in shared library which is
714 invoked in Wine code and generate GPF. debugger stops somewhere in
715 aplication's InitInstance !!! - and the stack is broken so I can't
716 catch where exactly the problem is. Any hints are welcome. I'm using
717 Wine-2000517 shapshot downloaded form Wine.datapary.no 
719 TNX.
721 Damyan
722 p.s.
723 If any of You is interested in details I can share my
724 experience.
727 From: Damyan Ognyanoff <Damyan@rocketmail.com>
728 Subject: Re: Wine MFC info request
731 my MFC is from VC6.0 with SP3
732 MFC Bulid: (form  afxbld_.h)
733     #define _MFC_BUILD 8447
734     #define _MFC_USER_BUILD "8447"
735     #define _MFC_RBLD 0
736 mfcdll.rc
737     FILEVERSION       6,0,_MFC_BUILD,_MFC_RBLD
738     PRODUCTVERSION    6,0,0,0
740 Hints:
741     1. Wine include files
743 In some of them you will find error about '__attribute__' all kinds of
744 similar errors can be fixed using proper typedefs first example :
746 typedef BOOL (CALLBACK *DLGPROC)(HWND,UINT,WPARAM,LPARAM);
748 must be converted to
750 typedef BOOL CALLBACK (*DLGPROC)(HWND,UINT,WPARAM,LPARAM);
752 and the second kind is something like
754 TYPE* WINAPI SomeFunction(HWND param1,UINT param2);
756 The problem here is a TYPE* or TYPE& (in some of mfc files) the
757 workaround is to declare a type before:
759 typedef TYPE* TYPEPtr; 
763 typedef TYPE& TYPERef;
765 and declaration will look like:
767 TYPEPtr WINAPI SomeFunction(HWND param1,UINT param2);
769 note: don't miss a 'struct' when you define struct type pointers. I
770 miss it and get a lot of problems compiling MFC:
773 struct _TEB;
774 typedef !!!struct!!! _TEB* P_TEB;
775 extern inline P_TEB WINAPI NtCurrentTeb(void);
778 Those conversions are semanticaly the same as above but g++ compile
779 them and generate proper code to invoke __stdcall kind of functions
781 in some of Wine/obj_XXX.h files: Wine/obj_base.h - there are a lot of
782 defines's that are used to declare a COM interfaces
784 #define ICOM_METHOD(ret,xfn) \
785      public: virtual ret (CALLBACK xfn)(void) = 0;
787 will be (for all of them that are related to C++ (watch #ifdef's
788 carefully)):
790 #define ICOM_METHOD(ret,xfn) \
791      public: virtual ret CALLBACK (xfn)(void) = 0;
793 and the second tip is an error when compiler stops on line like:
795    ICOM_DEFINE(ISomeInterfase,IUnknown)
797 watch method declarations above to find something like:
799 ICOM_METHOD1(TYPE*,MethodName, DWORD,dwParam)
801 and replace TYPE* with proper TYPEPtr type. In many cases You will see
802 void* which can be replaced simply by LPVOID.
804 qthere are several errors related to anonymous structs and unions but
805 they can be avoided with proper - #ifdef __cplusplus
807 This is all about Wine headers I think. If you find something that I
808 miss type a line of mail to me.
810 2. MFC
811 The rules are the same with some new issues:
813 virtual BOOL Method1(int param1, BOOL (CALLBACK *param2)
814 (HWND,UINT,WPARAM,LPARAM));
816 don't compile. I remove a function pointer declaration
817 outside method:
819 typedef BOOL CALLBACK
820 (*param2Type)(HWND,UINT,WPARAM,LPARAM);
822 virtual BOOL Method1(int param1, param2Type param2);
824 I didn't apply this technique to a operator new
825 definitions:
827         void* AFXAPI operator new(size_t nSize);
829 so i remove AFXAPI from these declarations:
831 I got some missed #defines from commctrl.h and I added
832 them form VC6.0 include.
834 these are my defines form Makefile which I used to
835 compile MFC
837 -DTWINE_NO_CMONIKER \ -- this is related to exclude
838 CMonikerFile 
839 -D__urlmon_h__ \ -- Wine didn't have URL interfaces 
840 -D_AFX_NO_OLEDB_SUPPORT \
841 -D_WIN32  \
842 -DNOWIN98  \ -- this is used to exclude all
843 unimplemented classes from commctrl 
844 -D_AFX_PACKING \
845 -D_AFX_NO_DHTML_SUPPORT \
846 -D_AFX_NO_SOCKET_SUPPORT \
847 -D_AFX_NO_SYNC_SUPPORT \
848 -D_AFX_NO_OCX_SUPPORT  \
849 -D_AFX_PORTABLE \
850 -D_AFX_OLD_EXCEPTIONS \
851 -D_AFX_NO_SOCKET_SUPPORT \
852 -D_AFX_NO_DEBUG_CRT \
853 -D_AFX_NO_DAO_SUPPORT \
854 -D_AFX_NO_OCC_SUPPORT \
855 -D_AFX_NO_INET_SUPPORT \
856 -D_AFX_NO_RICHEDIT_SUPPORT  \
857 -D_X86_ \
858 -DLONGHANDLES
860 may be you will try to enable some of features of mfc I tested only
861 -D_AFX_NO_OCC_SUPPORT but got missing interfaces from Wine
863 in file afxcom_.h
864 - _CIP<_Interface, _IID>::~_CIP<_Interface, _IID>()
865 + _CIP<_Interface, _IID>::~_CIP()
867 in file afxtempl.h
868 -       BOOL Lookup(BASE_CLASS::BASE_ARG_KEY key,
869 VALUE& rValue) const
870 -               { return BASE_CLASS::Lookup(key,
871 (BASE_CLASS::BASE_VALUE&)rValue); }
872 +       BOOL Lookup(typename BASE_CLASS::BASE_ARG_KEY
873 key, VALUE& rValue) const
874 +               { return BASE_CLASS::Lookup(key,
875 (typename BASE_CLASS::BASE_VALUE&)rValue); }
877 and all releated errors can be fixed in this way.
879 3. spec file
880     name        mfc42
881     type        win32
882     rsrc        mfc42
884     10 stdcall WinMain(long long ptr long) WinMain
886 4. linking 
887     use -rdynamic wnen link libmfc.so to get ARGV and
888 ARGC from loader
889     
890 5. I didn'n build a extention dll with Wine but I suspect that there
891 will be some problems releated to a chaining Runtime classes form MFC
892 to a new dll
894 6. build your app as a MODULE too.
896 7. make a loader and in it's _WinMain:
897 ... includes are here
898 iint PASCAL (*winMain)(HINSTANCE,HINSTANCE,LPSTR,int) =
900 my app uses these to manage filenames
901 VOID __cdecl (*_splitpath1)(LPCSTR path, LPSTR drive,
902 LPSTR directory, LPSTR filename, LPSTR extension ) =
903 NULL;
904 VOID __cdecl _splitpath(LPCSTR path, LPSTR drive,
905 LPSTR directory, LPSTR filename, LPSTR extension )
907     if (_splitpath1)
908         _splitpath1(path, drive, directory, filename,
909 extension );
911 VOID __cdecl (*_makepath1)(LPSTR path, LPCSTR drive,
912 LPCSTR directory, LPCSTR filename, LPCSTR extension )
913 = NULL;
914 VOID __cdecl _makepath(LPSTR path, LPCSTR drive,
915 LPCSTR directory, LPCSTR filename, LPCSTR extension )
917     if (_makepath1)
918         _makepath1(path, drive, directory, filename,
919 extension);
921 int PASCAL _WinMain(HINSTANCE h,HINSTANCE h1,LPSTR
922 lpszCmdParam,int c)
924   HINSTANCE hInstance,hins,hlib,htst,hform,himag,hexe;
925         int retv;
927         hins = LoadLibrary("CRTDLL.DLL");
928         _splitpath1 = GetProcAddress(hins,
929 "_splitpath");
930         _makepath1 = GetProcAddress(hins,
931 "_makepath");
932         hins = LoadLibrary("COMCTL32.DLL");
933         hins = LoadLibrary("COMDLG32.DLL");
936         hins = dlopen("libmfc42.so",2);
937         hlib = LoadLibrary("mfc42");
938         himag = dlopen("libmxformatslib.so",2);
939         hform = LoadLibrary("mxformatslib");
940         hexe = dlopen("libmxpaint.so",2);
941         htst = LoadLibrary("mxpaint");
943         winMain = GetProcAddress(hlib, "WinMain");
944         if (winMain)
945         {
946           retv = winMain (htst,    // note the > htst
947 < HERE
948                   0,            
949                   lpszCmdParam, 
950                   SW_NORMAL);   
951         }
952     FreeLibrary(htst);
953     FreeLibrary(hform);
954     FreeLibrary(hlib);
955     dlclose(hexe);
956     dlclose(himag);
957     dlclose(hins);
958     return retv;
960 the spec for loader is:
961 name    c10
962 mode    guiexe
963 type    win32
964 init    _WinMain
966 please find attached a Makefile which i use to build
969 Regards 
970 Damyan.
972  LocalWords:  WineLib HOWTO Jun vs DLLs DLL MFC NT FIXME CrypKey Kenonic API TM
973  LocalWords:  WinMain GPL LGPL EULA winver nt dos unix tr CR LF gcc libtest dll
974  LocalWords:  guiexe init cuiexe pic lwine lncurses lm lutil ldl wav winmm wrc
975  LocalWords:  elfdll edrlib Petzold Patrik Stridvall int michael cardenas msgs
976  LocalWords:  wireoff msgs wireon app devel cvs ifdef Corel Damyan Ognyanoff IE
977  LocalWords:  Gavriel MFC's Wine's VC underdocumented Google fromdos GCCs apps
978  LocalWords:  fpermissive whereever symlink filesystem tarball RFC linux Urk SP
979  LocalWords:  misspoke TWine structs DNO XXX Microsofts occassionaly WineHQ Gav
980  LocalWords:  TransGaming alright hairball Jer Visi IMHO MSVC nonexclusive mfc
981  LocalWords:  mfc's destructors zombi GPF aplication's InitInstance shapshot rc
982  LocalWords:  TNX Bulid afxbld RBLD mfcdll FILEVERSION PRODUCTVERSION BOOL HWND
983  LocalWords:  CALLBACK DLGPROC UINT WPARAM LPARAM WINAPI SomeFunction param TEB
984  LocalWords:  param TYPEPtr TYPERef struct struct NtCurrentTeb semanticaly obj
985  LocalWords:  stdcall obj defines's COM ICOM ret xfn ifdef's ISomeInterfase URL
986  LocalWords:  IUnknown MethodName DWORD dwParam LPVOID qthere cplusplus AFXAPI
987  LocalWords:  nSize commctrl DTWINE CMONIKER CMonikerFile urlmon AFX OLEDB SYNC
988  LocalWords:  DNOWIN DHTML OCX DAO OCC INET RICHEDIT DLONGHANDLES afxcom CIP SW
989  LocalWords:  IID CIP IID afxtempl ARG rValue const typename releated rsrc ptr
990  LocalWords:  rdynamic wnen libmfc ARGV ARGC didn'n extention iint winMain hins
991  LocalWords:  HINSTANCE HINSTANCE LPSTR cdecl splitpath LPCSTR makepath hlib
992  LocalWords:  lpszCmdParam hInstance htst hform himag hexe retv LoadLibrary
993  LocalWords:  CRTDLL GetProcAddress COMCTL COMDLG dlopen libmxformatslib
994  LocalWords:  mxformatslib libmxpaint mxpaint FreeLibrary dlclose