blob: 50726c4e5eadd51f0c39ebfa61b54446ae724317 [file] [log] [blame]
Douglas Ridgway692389d1998-11-22 16:56:44 +00001This document should help new developers get started. Like all of Wine, it
2is a work in progress.
Alexandre Julliarddba420a1994-02-02 06:48:31 +00003
Alexandre Julliard889f7421997-04-15 17:19:52 +00004SOURCE TREE STRUCTURE
5=====================
6
Douglas Ridgway692389d1998-11-22 16:56:44 +00007The Wine source tree is loosely based on the original Windows modules.
8Most of the source is concerned with implementing the Wine API, although
9there are also various tools, documentation, sample Winelib code, and
10code specific to the binary loader.
Alexandre Julliard889f7421997-04-15 17:19:52 +000011
Douglas Ridgway692389d1998-11-22 16:56:44 +000012Wine API directories:
13---------------------
Alexandre Julliard889f7421997-04-15 17:19:52 +000014
15KERNEL:
16
17 files/ - file I/O
18 loader/ - Win16-, Win32-binary loader
19 memory/ - memory management
Douglas Ridgway692389d1998-11-22 16:56:44 +000020 msdos/ - DOS features and BIOS calls (interrupts)
Alexandre Julliard889f7421997-04-15 17:19:52 +000021 scheduler/ - process and thread management
22
23GDI:
24
25 graphics/ - graphics drivers
26 graphics/x11drv/ - X11 display driver
27 graphics/metafiledrv/ - metafile driver
28 objects/ - logical objects
29
30USER:
31
32 controls/ - built-in widgets
33 resources/ - built-in dialog resources
34 windows/ - window management
35
Douglas Ridgway692389d1998-11-22 16:56:44 +000036Other DLLs:
37
38 dlls/*/ - Other system DLLs implemented by Wine
39
Alexandre Julliard889f7421997-04-15 17:19:52 +000040Miscellaneous:
41
Douglas Ridgway692389d1998-11-22 16:56:44 +000042 misc/ - shell, registry, winsock, etc.
Alexandre Julliard889f7421997-04-15 17:19:52 +000043 multimedia/ - multimedia driver
Douglas Ridgway692389d1998-11-22 16:56:44 +000044 ipc/ - SysV IPC based interprocess communication
Alexandre Julliard889f7421997-04-15 17:19:52 +000045 win32/ - misc Win32 functions
46
47Tools:
Douglas Ridgway692389d1998-11-22 16:56:44 +000048------
Alexandre Julliard889f7421997-04-15 17:19:52 +000049
Douglas Ridgway692389d1998-11-22 16:56:44 +000050 rc/ - old resource compiler
51 tools/ - relay code builder, new rc, etc.
Alexandre Julliard889f7421997-04-15 17:19:52 +000052 documentation/ - some documentation
53
54
Douglas Ridgway692389d1998-11-22 16:56:44 +000055Binary loader specific directories:
56-----------------------------------
Alexandre Julliard889f7421997-04-15 17:19:52 +000057
58 debugger/ - built-in debugger
59 if1632/ - relay code
60 miscemu/ - hardware instruction emulation
61 graphics/win16drv/ - Win16 printer driver
62
Douglas Ridgway692389d1998-11-22 16:56:44 +000063Winelib specific directories:
Alexandre Julliard889f7421997-04-15 17:19:52 +000064-----------------------------
65
Douglas Ridgway692389d1998-11-22 16:56:44 +000066 library/ - Required code for programs using Winelib
67 libtest/ - Small samples and tests
68 programs/ - Extended samples / system utilities
Alexandre Julliard889f7421997-04-15 17:19:52 +000069
Alexandre Julliardc7c217b1998-04-13 12:21:30 +000070IMPLEMENTING NEW API CALLS
71==========================
72
73This is the simple version, and covers only Win32. Win16 is slightly uglier,
74because of the Pascal heritage and the segmented memory model.
75
76All of the Win32 APIs known to Wine are listed in [relay32/*.spec]. An
77unimplemented call will look like (from gdi32.spec)
78 269 stub PolyBezierTo
79To implement this call, you need to do the following four things.
80
811. Find the appropriate parameters for the call, and add a prototype to
82[include/windows.h]. In this case, it might look like
83 BOOL32 WINAPI PolyBezierTo32(HDC32, LPCVOID, DWORD);
84 #define PolyBezierTo WINELIB_NAME(PolyBezierTo)
85Note the use of the #define for Winelib. See below for discussion of
86function naming conventions.
87
882. Modify the .spec file to tell Wine that the function has an
89implementation, what the parameters look like and what Wine function
90to use for the implementation. In Win32, things are simple--everything
91is 32-bits. However, the relay code handles pointers and pointers to
92strings slightly differently, so you should use 'str' and 'wstr' for
93strings, 'ptr' for other pointer types, and 'long' for everything else.
94 269 stdcall PolyBezierTo(long ptr long) PolyBezierTo32
95The 'PolyBezierTo32' at the end of the line is which Wine function to use
96for the implementation.
97
983. Implement the function as a stub. Once you add the function to the .spec
99file, you must add the function to the Wine source before it will link.
100Add a function called 'PolyBezierTo32' somewhere. Good things to put
101into a stub:
102 o a correct prototype, including the WINAPI
103 o header comments, including full documentation for the function and
104 arguments
105 o A FIXME message and an appropriate return value are good things to
106 put in a stub.
107
108 /************************************************************
109 * PolyBezierTo32 (GDI32.269) Draw many Bezier curves
110 *
111 * BUGS
112 * Unimplemented
113 */
114 BOOL32 WINAPI PolyBezierTo32(HDC32 hdc, LPCVOID p, DWORD count) {
115 /* tell the user they've got a substandard implementation */
116 FIXME(gdi, ":(%x,%p,%d): stub\n", hdc, p, count);
117 /* some programs may be able to compensate,
118 if they know what happened */
119 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
120 return FALSE; /* error value */
121 }
122
1234. Implement and test the function.
Alexandre Julliard889f7421997-04-15 17:19:52 +0000124
Alexandre Julliard1285c2f1996-05-06 16:06:24 +0000125MEMORY AND SEGMENTS
126===================
Alexandre Julliarddba420a1994-02-02 06:48:31 +0000127
128NE (Win16) executables consist of multiple segments. The Wine loader
Alexandre Julliarde2abbb11995-03-19 17:39:39 +0000129loads each segment into a unique location in the Wine processes memory
130and assigns a selector to that segment. Because of this, it's not
131possible to exchange addresses freely between 16-bit and 32-bit code.
132Addresses used by 16-bit code are segmented addresses (16:16), formed
133by a 16-bit selector and a 16-bit offset. Those used by the Wine code
134are regular 32-bit linear addresses.
Alexandre Julliarddba420a1994-02-02 06:48:31 +0000135
Alexandre Julliard1e37a181996-08-18 16:21:52 +0000136There are four ways to obtain a segmented pointer:
137 - Use the SEGPTR_* macros in include/heap.h (recommended).
Alexandre Julliarde2abbb11995-03-19 17:39:39 +0000138 - Allocate a block of memory from the global heap and use
139 WIN16_GlobalLock to get its segmented address.
140 - Allocate a block of memory from a local heap, and build the
141 segmented address from the local heap selector (see the
142 USER_HEAP_* macros for an example of this).
143 - Declare the argument as 'segptr' instead of 'ptr' in the spec file
144 for a given API function.
Alexandre Julliarddba420a1994-02-02 06:48:31 +0000145
Alexandre Julliarde2abbb11995-03-19 17:39:39 +0000146Once you have a segmented pointer, it must be converted to a linear
147pointer before you can use it from 32-bit code. This can be done with
148the PTR_SEG_TO_LIN() and PTR_SEG_OFF_TO_LIN() macros. The linear
149pointer can then be used freely with standard Unix functions like
150memcpy() etc. without worrying about 64k boundaries. Note: there's no
151easy way to convert back from a linear to a segmented address.
Alexandre Julliarddba420a1994-02-02 06:48:31 +0000152
Alexandre Julliarde2abbb11995-03-19 17:39:39 +0000153In most cases, you don't need to worry about segmented address, as the
154conversion is made automatically by the callback code and the API
155functions only see linear addresses. However, in some cases it is
156necessary to manipulate segmented addresses; the most frequent cases
157are:
158 - API functions that return a pointer
159 - lParam of Windows messages that point to a structure
160 - Pointers contained inside structures accessed by 16-bit code.
Alexandre Julliarddba420a1994-02-02 06:48:31 +0000161
Alexandre Julliarde2abbb11995-03-19 17:39:39 +0000162It is usually a good practice to used the type 'SEGPTR' for segmented
163pointers, instead of something like 'LPSTR' or 'char *'. As SEGPTR is
164defined as a DWORD, you'll get a compilation warning if you mistakenly
165use it as a regular 32-bit pointer.
Alexandre Julliarddba420a1994-02-02 06:48:31 +0000166
Alexandre Julliard1285c2f1996-05-06 16:06:24 +0000167
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000168STRUCTURE PACKING
169=================
170
171Under Windows, data structures are tightly packed, i.e. there is no
172padding between structure members. On the other hand, by default gcc
173aligns structure members (e.g. WORDs are on a WORD boundary, etc.).
174This means that a structure like
175
176struct { BYTE x; WORD y; };
177
178will take 3 bytes under Windows, but 4 with gcc, because gcc will add a
179dummy byte between x and y. To have the correct layout for structures
180used by Windows code, you need to use the WINE_PACKED attribute; so you
181would declare the above structure like this:
182
183struct { BYTE x; WORD y WINE_PACKED; };
184
185You have to do this every time a structure member is not aligned
186correctly under Windows (i.e. a WORD not on an even address, or a
187DWORD on a address that is not a multiple of 4).
188
189
Alexandre Julliard1285c2f1996-05-06 16:06:24 +0000190NAMING CONVENTIONS FOR API FUNCTIONS AND TYPES
191==============================================
192
193In order to support both Win16 and Win32 APIs within the same source
Douglas Ridgway692389d1998-11-22 16:56:44 +0000194code, the following convention must be used in naming all API
Alexandre Julliard1285c2f1996-05-06 16:06:24 +0000195functions and types. If the Windows API uses the name 'xxx', the Wine
196code must use:
197
198 - 'xxx16' for the 16-bit version,
199 - 'xxx32' for the 32-bit version when no ASCII/Unicode strings are
200 involved,
201 - 'xxx32A' for the 32-bit version with ASCII strings,
202 - 'xxx32W' for the 32-bit version with Unicode strings.
203
204You should then use the macros WINELIB_NAME[_AW](xxx) or
205DECL_WINELIB_TYPE[_AW](xxx) (defined in include/wintypes.h) to define
Douglas Ridgway692389d1998-11-22 16:56:44 +0000206the correct 'xxx' function or type for Winelib. When compiling Wine
207itself, 'xxx' is _not_ defined, meaning that code inside of Wine must
208always specify explicitly the 16-bit or 32-bit version.
Alexandre Julliard1285c2f1996-05-06 16:06:24 +0000209
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000210If 'xxx' is the same in Win16 and Win32, or if 'xxx' is Win16 only,
211you can simply use the same name as Windows, i.e. just 'xxx'. If
212'xxx' is Win32 only, you can use 'xxx' if there are no strings
213involved, otherwise you must use the 'xxx32A' and 'xxx32W' forms.
Alexandre Julliard1285c2f1996-05-06 16:06:24 +0000214
215Examples:
216
217typedef short INT16;
218typedef int INT32;
219DECL_WINELIB_TYPE(INT);
220
221typedef struct { /* Win32 ASCII data structure */ } WNDCLASS32A;
222typedef struct { /* Win32 Unicode data structure */ } WNDCLASS32W;
223typedef struct { /* Win16 data structure */ } WNDCLASS16;
224DECL_WINELIB_TYPE_AW(WNDCLASS);
225
226ATOM RegisterClass16( WNDCLASS16 * );
227ATOM RegisterClass32A( WNDCLASS32A * );
228ATOM RegisterClass32W( WNDCLASS32W * );
229#define RegisterClass WINELIB_NAME_AW(RegisterClass)
230
231The Winelib user can then say:
232
233 INT i;
234 WNDCLASS wc = { ... };
235 RegisterClass( &wc );
236
237and this will use the correct declaration depending on the definition
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000238of the symbols WINELIB and UNICODE.
Alexandre Julliard1285c2f1996-05-06 16:06:24 +0000239
240
241API ENTRY POINTS
242================
Alexandre Julliarddba420a1994-02-02 06:48:31 +0000243
244Because Win16 programs use a 16-bit stack and because they can only
245call 16:16 addressed functions, all API entry points must be at low
246address offsets and must have the arguments translated and moved to
247Wines 32-bit stack. This task is handled by the code in the "if1632"
248directory. To define a new API entry point handler you must place a
249new entry in the appropriate API specification file. These files are
Alexandre Julliardca22b331996-07-12 19:02:39 +0000250named *.spec. For example, the API specification file for the USER
251DLL is contained in the file user.spec. These entries are processed
252by the "build" program to create an assembly file containing the entry
253point code for each API call. The format of the *.spec files is
Alexandre Julliard8d24ae61994-04-05 21:42:43 +0000254documented in the file "tools/build-spec.txt".
255
Alexandre Julliard1285c2f1996-05-06 16:06:24 +0000256
257DEBUG MESSAGES
258==============
Alexandre Julliardaca05781994-10-17 18:12:41 +0000259
260To display a message only during debugging, you normally write something
261like this:
262
Alexandre Julliard54c27111998-03-29 19:44:57 +0000263 TRACE(win,"abc..."); or
264 FIXME(win,"abc..."); or
265 WARN(win,"abc..."); or
266 ERR(win,"abc...");
Alexandre Julliardaca05781994-10-17 18:12:41 +0000267
Alexandre Julliard54c27111998-03-29 19:44:57 +0000268depending on the seriousness of the problem. (documentation/degug-msgs
269explains when it is appropriate to use each of them)
Alexandre Julliardaca05781994-10-17 18:12:41 +0000270
Alexandre Julliard54c27111998-03-29 19:44:57 +0000271These macros are defined in include/debug.h. The macro-definitions are
272generated by the shell-script tools/make_debug. It scans the source
273code for symbols of this forms and puts the necessary macro
274definitions in include/debug.h and include/debugdefs.h. These macros
275test whether the debugging "channel" associated with the first
276argument of these macros (win in the above example) is enabled and
277thus decide whether to actually display the text. In addition you can
278change the types of displayed messages by supplying the "-debugmsg"
279option to Wine. If your debugging code is more complex than just
280printf, you can use the symbols TRACE_ON(xxx), WARN_ON(xxx),
281ERR_ON(xxx) and FIXME_ON(xxx) as well. These are true when channel xxx
282is enabled, either permanent or in the command line. Thus, you can
283write:
Alexandre Julliardaca05781994-10-17 18:12:41 +0000284
Alexandre Julliard54c27111998-03-29 19:44:57 +0000285 if(TRACE_ON(win))DumpSomeStructure(&str);
Alexandre Julliard234bc241994-12-10 13:02:28 +0000286
Alexandre Julliard234bc241994-12-10 13:02:28 +0000287Don't worry about the inefficiency of the test. If it is permanently
Alexandre Julliard54c27111998-03-29 19:44:57 +0000288disabled (that is TRACE_ON(win) is 0 at compile time), the compiler will
Alexandre Julliard234bc241994-12-10 13:02:28 +0000289eliminate the dead code.
Alexandre Julliardaca05781994-10-17 18:12:41 +0000290
Alexandre Julliardaca05781994-10-17 18:12:41 +0000291You have to start tools/make_debug only if you introduced a new macro,
Alexandre Julliard54c27111998-03-29 19:44:57 +0000292e.g. TRACE(win32).
293
294For more info about debugging messages, read:
295
296documentation/debug-msgs
297
Alexandre Julliard23946ad1997-06-16 17:43:53 +0000298
299MORE INFO
300=========
301
Alexandre Julliard33072e11997-06-29 18:08:02 +00003021. There is a FREE online version of the MSDN library (including
303 documentation for the Win32 API) on http://www.microsoft.com/msdn/
Alexandre Julliard23946ad1997-06-16 17:43:53 +0000304
Alexandre Julliard33072e11997-06-29 18:08:02 +00003052. http://www.sonic.net/~undoc/bookstore.html
Alexandre Julliard23946ad1997-06-16 17:43:53 +0000306
Alexandre Julliard33072e11997-06-29 18:08:02 +00003073. In 1993 Dr. Dobbs Journal published a column called "Undocumented Corner".
308
3094. You might want to check out BYTE from December 1983 as well :-)
Alexandre Julliard23946ad1997-06-16 17:43:53 +0000310