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