8 4901 HW Oosterhout (NB)
13 WARNING: This HOWTO is incomplete. I expect to add to it on a weekly
14 basis until it is complete.
16 =====================================================================
20 I. Introduction: Wine vs. WineLib
26 IV. File Format Conversion
28 V. Compiling A Simple Win32 Program
30 VI. Compiling A Win32 Program With Resources
39 A. Using a native MFC DLL
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
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
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.
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
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
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
216 FIXME: give info on Wine command line options to control error
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
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
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 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:
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,
296 During compilation of the hello2 executable, the following command is
299 ../tools/winebuild/winebuild -fPIC -o hello2.spec.c -spec hello2.spec
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().
310 FIXME: for WineLib users -- is there ever a need to not specify -fPIC?
312 Now the compilation of hello2 can proceed as any other compilation for
315 gcc -c -I. -I. -I../include -I../include -g -O2 -Wall -D_REENTRANT \
316 -I/usr/X11R6/include -o hello2.o hello2.c
318 FIXME: -D_REENTRANT why?
319 FIXME: explain compiler options
321 to compile the window program itself and
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
326 to compile the main() and the glue code. Finally,
328 gcc -o hello2 hello2.o hello2.spec.o -L../dlls -L.. -lwine -lncurses
331 FIXME: explain linker options
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
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
353 If you need to list multiple DLLs, then the import specification can
354 appear multiple times.
356 FIXME: can multiple libraries appear on one import line?
358 VI. Compiling A Win32 Program With Resources
360 FIXME: to be continued.
362 Go through hello world example 3.
370 FIXME: to be continued.
371 QUESTION: what are so DLL and elfdll. I think I have been doing so
374 Go over an example similar to edrlib in Petzold.
377 A. Using a native MFC DLL
380 FIXME: to be continued.
382 =====================================================================
385 Until this HOWTO is complete, I will document who gives me what
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
393 First of all WineLib suppport for Win16 has been discontinued
394 for quite some time, because:
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.
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
409 From: michael cardenas <mbc@deneba.com>
410 To: wilbur.dale@lumin.nl
411 Date: Mon, 5 Jun 2000 13:19:34 -0400
413 a few things you should mention...
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
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.
425 - you probably want to compile your WineLib with --disable-debugger, at
426 least for the release version of your app.
429 http://fgouget/wine/winelib-en.shtml
431 =====================================================================
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.
437 Before I write more detailed info on compiling MFC I have three
438 questions. The info I have mentions three problems:
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++
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?
449 3. Microsoft extensions to the C++ syntax. Do the extensions Corel
450 made to gcc 2.95 handle this? If so, how?
452 If you have info that needs to be added, send me email at
453 <wilbur.dale@lumin.nl> and I will add it.
455 =====================================================================
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.
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>
473 From: Ian Schmidt <ischmidt@cfl.rr.com>
474 Subject: Re: WineLib and MFC
476 "Wilbur N. Dale" wrote:
478 > What is the status of MFC under WineLib?
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
488 > Which versions of MFC, if any?
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.
495 > Is there any documentation on how to compile MFC for WineLib? If so
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.
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
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).
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.
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
524 - Be prepared to have to rename and/or symlink headers, unless you
525 compile on a case-insensitive filesystem :)
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.
532 Sorry I can't help you more, but good luck!
538 From: Jeremy White <jwhite@codeweavers.com>
539 Subject: Re: RFC: Wine 1.0
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
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 ?
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.
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:
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.
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.
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).
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
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
591 I hope this helps. Sorry for the earlier deceptive post.
595 From: Gavriel State <gav@magmacom.com>
596 Subject: Re: MFC questions
598 "Wilbur N. Dale" wrote:
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.
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.
622 TransGaming Technologies Inc.
625 From: Jeremy White <jwhite@codeweavers.com>
626 Subject: Re: MFC questions
628 "Wilbur N. Dale" wrote:
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.
637 Wilbur, I personally think that this is the 'right' approach, although
638 approach #2 may prove faster.
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>).
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).
653 p.s. Stick with Visi C++ 5. IMHO its MFC license is cleaner than that
656 From: Gavriel State <gav@magmacom.com>
657 Subject: The MSVC++ 6.0 license
660 > p.s. Stick with Visi C++ 5. IMHO its MFC license is cleaner than that
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
671 The relevant portion of the original EULA:
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]
681 3. Section 1.1 of the EULA is deleted in its entirety and replaced
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]
689 Disclaimer - I am not a lawyer, but I've spent lots of time with them
690 investigating software licenses.
697 TransGaming Technologies Inc.
700 From: Damyan Ognyanoff <Damyan@rocketmail.com>
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
720 If any of You is interested in details I can share my
724 From: Damyan Ognyanoff <Damyan@rocketmail.com>
725 Subject: Re: Wine MFC info request
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"
734 FILEVERSION 6,0,_MFC_BUILD,_MFC_RBLD
735 PRODUCTVERSION 6,0,0,0
738 1. Wine include files
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 :
743 typedef BOOL (CALLBACK *DLGPROC)(HWND,UINT,WPARAM,LPARAM);
747 typedef BOOL CALLBACK (*DLGPROC)(HWND,UINT,WPARAM,LPARAM);
749 and the second kind is something like
751 TYPE* WINAPI SomeFunction(HWND param1,UINT param2);
753 The problem here is a TYPE* or TYPE& (in some of mfc files) the
754 workaround is to declare a type before:
756 typedef TYPE* TYPEPtr;
760 typedef TYPE& TYPERef;
762 and declaration will look like:
764 TYPEPtr WINAPI SomeFunction(HWND param1,UINT param2);
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:
771 typedef !!!struct!!! _TEB* P_TEB;
772 extern inline P_TEB WINAPI NtCurrentTeb(void);
775 Those conversions are semanticaly the same as above but g++ compile
776 them and generate proper code to invoke __stdcall kind of functions
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
781 #define ICOM_METHOD(ret,xfn) \
782 public: virtual ret (CALLBACK xfn)(void) = 0;
784 will be (for all of them that are related to C++ (watch #ifdef's
787 #define ICOM_METHOD(ret,xfn) \
788 public: virtual ret CALLBACK (xfn)(void) = 0;
790 and the second tip is an error when compiler stops on line like:
792 ICOM_DEFINE(ISomeInterfase,IUnknown)
794 watch method declarations above to find something like:
796 ICOM_METHOD1(TYPE*,MethodName, DWORD,dwParam)
798 and replace TYPE* with proper TYPEPtr type. In many cases You will see
799 void* which can be replaced simply by LPVOID.
801 qthere are several errors related to anonymous structs and unions but
802 they can be avoided with proper - #ifdef __cplusplus
804 This is all about Wine headers I think. If you find something that I
805 miss type a line of mail to me.
808 The rules are the same with some new issues:
810 virtual BOOL Method1(int param1, BOOL (CALLBACK *param2)
811 (HWND,UINT,WPARAM,LPARAM));
813 don't compile. I remove a function pointer declaration
816 typedef BOOL CALLBACK
817 (*param2Type)(HWND,UINT,WPARAM,LPARAM);
819 virtual BOOL Method1(int param1, param2Type param2);
821 I didn't apply this technique to a operator new
824 void* AFXAPI operator new(size_t nSize);
826 so i remove AFXAPI from these declarations:
828 I got some missed #defines from commctrl.h and I added
829 them form VC6.0 include.
831 these are my defines form Makefile which I used to
834 -DTWINE_NO_CMONIKER \ -- this is related to exclude
836 -D__urlmon_h__ \ -- Wine didn't have URL interfaces
837 -D_AFX_NO_OLEDB_SUPPORT \
839 -DNOWIN98 \ -- this is used to exclude all
840 unimplemented classes from commctrl
842 -D_AFX_NO_DHTML_SUPPORT \
843 -D_AFX_NO_SOCKET_SUPPORT \
844 -D_AFX_NO_SYNC_SUPPORT \
845 -D_AFX_NO_OCX_SUPPORT \
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 \
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
861 - _CIP<_Interface, _IID>::~_CIP<_Interface, _IID>()
862 + _CIP<_Interface, _IID>::~_CIP()
865 - BOOL Lookup(BASE_CLASS::BASE_ARG_KEY key,
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); }
874 and all releated errors can be fixed in this way.
881 10 stdcall WinMain(long long ptr long) WinMain
884 use -rdynamic wnen link libmfc.so to get ARGV and
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
891 6. build your app as a MODULE too.
893 7. make a loader and in it's _WinMain:
894 ... includes are here
895 iint PASCAL (*winMain)(HINSTANCE,HINSTANCE,LPSTR,int) =
897 my app uses these to manage filenames
898 VOID __cdecl (*_splitpath1)(LPCSTR path, LPSTR drive,
899 LPSTR directory, LPSTR filename, LPSTR extension ) =
901 VOID __cdecl _splitpath(LPCSTR path, LPSTR drive,
902 LPSTR directory, LPSTR filename, LPSTR extension )
905 _splitpath1(path, drive, directory, filename,
908 VOID __cdecl (*_makepath1)(LPSTR path, LPCSTR drive,
909 LPCSTR directory, LPCSTR filename, LPCSTR extension )
911 VOID __cdecl _makepath(LPSTR path, LPCSTR drive,
912 LPCSTR directory, LPCSTR filename, LPCSTR extension )
915 _makepath1(path, drive, directory, filename,
918 int PASCAL _WinMain(HINSTANCE h,HINSTANCE h1,LPSTR
921 HINSTANCE hInstance,hins,hlib,htst,hform,himag,hexe;
924 hins = LoadLibrary("CRTDLL.DLL");
925 _splitpath1 = GetProcAddress(hins,
927 _makepath1 = GetProcAddress(hins,
929 hins = LoadLibrary("COMCTL32.DLL");
930 hins = LoadLibrary("COMDLG32.DLL");
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");
940 winMain = GetProcAddress(hlib, "WinMain");
943 retv = winMain (htst, // note the > htst
957 the spec for loader is:
963 please find attached a Makefile which i use to build
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