1 This document should help new developers get started. Like all of Wine, it
8 The Wine source tree is loosely based on the original Windows modules.
9 Most of the source is concerned with implementing the Wine API, although
10 there are also various tools, documentation, sample Winelib code, and
11 code specific to the binary loader. Note that several of the libraries
12 listed here are "stubbed out", meaning they still need to be implemented.
17 advapi32/ - Crypto, systeminfo, security, eventlogging
18 avicap32/ - AVI capture window class
19 avifil32/ - COM object to play AVI files
20 cabinet/ - Cabinet file interface
21 capi2032/ - Wrapper library for CAPI4Linux access
22 cfgmgr32/ - Config manager
23 comcat/ - Component category manager
24 comctl32/ - Common controls
25 commdlg/ - Common dialog boxes (both 16 & 32 bit)
26 crtdll/ - Old C runtime library
27 crypt32/ - Cryptography
28 ctl3d/ - 3D Effects for Common GUI Components
29 d3d8/ - Direct3D (3D graphics)
30 d3d9/ - Direct3D (3D graphics)
31 d3dim/ - Direct3D Immediate Mode
32 d3dx8/ - Direct3D (3D graphics)
33 dciman32/ - DCI Manager (graphics)
34 ddraw/ - DirectDraw (graphics)
35 devenum/ - Device enumeration (part of DirectShow)
36 dinput/ - DirectInput (device input)
37 dinput8/ - DirectInput (device input)
39 dmcompos/ - DirectMusic
41 dmloader/ - DirectMusic
42 dmscript/ - DirectMusic
43 dmstyle/ - DirectMusic
44 dmsynth/ - DirectMusic
46 dmusic32/ - DirectMusic
47 dplay/ - DirectPlay (networking)
48 dplayx/ - DirectPlay (networking)
49 dpnhpast/ - DirectPlay NAT Helper
50 dsound/ - DirectSound (audio)
52 glu32/ - OpenGL Utility library (graphics)
53 glut32/ - OpenGL Utility Toolkit
54 icmp/ - ICMP protocol (networking)
55 imagehlp/ - PE (Portable Executable) Image Helper lib
56 imm32/ - Input Method Manager
57 iphlpapi/ - IP Helper API
58 kernel/ - The Windows kernel
59 lzexpand/ - Lempel-Ziv compression/decompression
60 mapi32/ - Mail interface
61 mpr/ - Multi-Protocol Router (networking)
62 msacm/ - Audio Compression Manager (multimedia)
63 msacm/imaadp32/ - IMA ADPCM Audio Codec
64 msacm/msadp32/ - MS ADPCM Audio Codec
65 msacm/msg711/ - MS G711 Audio Codec (includes A-Law & MU-Law)
66 msacm/winemp3/ - Mpeg Layer 3 Audio Codec
67 msdmo/ - DirectX Media Objects
68 mshtml/ - MS HTML component
69 msimg32/ - Gradient and transparency (graphics)
70 msisys/ - System information
71 msi/ - Microsoft Installer
72 msnet32/ - Network interface
73 msvcrt/ - C runtime library
74 msvcrt20/ - C runtime library version 2.0
75 msvcrtd/ - C runtime library debugging
76 msvideo/ - 16 bit video manager
77 msvideo/msrle32/ - Video codecs
78 mswsock/ - Misc networking
79 netapi32/ - Network interface
80 ntdll/ - NT implementation of kernel calls
81 odbc32/ - Open DataBase Connectivity driver manager
82 ole32/ - 32 bit OLE 2.0 libraries
83 oleacc/ - OLE accessibility support
84 oleaut32/ - 32 bit OLE 2.0 automation
85 olecli/ - 16 bit OLE client
86 oledlg/ - OLE 2.0 user interface support
87 olepro32/ - 32 bit OLE 2.0 automation
88 olesvr/ - 16 bit OLE server
89 opengl32/ - OpenGL implementation (graphics)
90 psapi/ - Process Status interface
91 qcap/ - DirectShow runtime
92 quartz/ - DirectShow runtime
93 rasapi32/ - Remote Access Server interface
94 richedit/ - Rich text editing control
95 rpcrt4/ - Remote Procedure Call runtime
96 serialui/ - Serial port property pages
97 setupapi/ - Setup interface
98 shdocvw/ - Shell document object and control
99 shfolder/ - Shell folder service
100 shell32/ - COM object implementing shell views
101 shlwapi/ - Shell Light-Weight interface
102 snmpapi/ - SNMP protocol interface (networking)
103 sti/ - Still Image service
104 tapi32/ - Telephone interface
105 ttydrv/ - TTY display driver (Wine specific)
106 twain/ - TWAIN Imaging device communications
107 unicows/ - Unicows replacement (Unicode layer for Win9x)
108 url/ - Internet shortcut shell extension
109 urlmon/ - URL Moniker allows binding to a URL (like KIO/gnome-vfs)
110 user/ - Window management, standard controls, etc.
111 uxtheme/ - Theme library
112 version/ - File installation library
113 win32s/ - 32-bit function access for 16-bit systems
114 winaspi/ - 16 bit Advanced SCSI Peripheral Interface
115 wined3d/ - Wine internal Direct3D helper
116 winedos/ - DOS features and BIOS calls (interrupts) (wine specific)
117 wineps/ - Postscript driver (Wine specific)
118 wininet/ - Internet extensions
119 winmm/ - Multimedia (16 & 32 bit)
120 winmm/joystick/ - Joystick driver
121 winmm/mcianim/ - MCI animation driver
122 winmm/mciavi/ - MCI video driver
123 winmm/mcicda/ - MCI audio CD driver
124 winmm/mciseq/ - MCI MIDI driver
125 winmm/mciwave/ - MCI wave driver
126 winmm/midimap/ - MIDI mapper
127 winmm/wavemap/ - Audio mapper
128 winmm/winealsa/ - ALSA audio driver
129 winmm/winearts/ - aRts audio driver
130 winmm/wineaudioio/ - audioio audio driver
131 winmm/winejack/ - JACK audio server driver
132 winmm/winenas/ - NAS audio driver
133 winmm/wineoss/ - OSS audio driver
134 winnls/ - National Language Support
135 winsock/ - Sockets 2.0 (networking)
136 wsock32/ - Sockets 1.1 (networking)
137 wintab32/ - Tablet device interface
138 winspool/ - Printing & Print Spooler
139 wintrust/ - Trust verification interface
140 wow32/ - WOW subsystem
141 x11drv/ - X11 display driver (Wine specific)
143 Winelib programs (under programs/):
144 -----------------------------------
146 avitools/ - AVI information viewer and player
147 clock/ - Graphical clock
148 cmdlgtst/ - Common dialog tests
149 control/ - Control panel
150 expand/ - Decompress Lempel-Ziv compressed archive
151 notepad/ - Notepad with RichEdit functionality
152 progman/ - Program manager
153 regedit/ - Registry editor
154 regsvr32/ - Register COM server
155 rpcss/ - RPC services
156 rundll32/ - Execute DLL functions directly
157 start/ - Replacement for start.exe
158 uninstaller/ - Remove installed programs
159 view/ - Metafile viewer
160 wcmd/ - Command line interface
161 wineboot/ - Wine bootstrap process
162 winecfg/ - Wine configuration utility
163 wineconsole/ - Console
165 winefile/ - File manager
166 winemenubuilder/ - Helper program for building Unix menu entries
167 winemine/ - Mine game
168 winepath/ - Translate between Wine and Unix paths
169 winetest/ - Wine testing shell
170 winevdm/ - Wine virtual DOS machine
171 winhelp/ - Help viewer
172 winver/ - Windows Version Program
175 Support programs, libraries, etc:
176 ---------------------------------
178 documentation/ - some documentation
179 documentation/samples - sample configuration files
180 include/ - Windows standard includes
181 include/msvcrt - MSVC compatible libc headers
182 include/wine - Wine specific headers
183 libs/ - the Wine libraries
184 libs/port/ - portability library
185 libs/unicode/ - Unicode support shared
186 libs/uuid/ - Windows-compatible UUID numbers
187 libs/wine/ - Wine bootstrap library
188 libs/wpp/ - C preprocessor
189 loader/ - the main Wine loader
190 server/ - the Wine server
191 tools/ - various tools used to build/check Wine
192 tools/widl - the IDL compiler
193 tools/winapi{,_check} - A Win32 API checker
194 tools/winebuild - Wine build tool
195 tools/winedump - a .DLL dump utility
196 tools/winegcc - a MinGW command line compatible gcc wrapper
197 tools/wmc - the message compiler
198 tools/wpp - the C pre-processor library
199 tools/wrc - the resource compiler
205 Note: these directories will ultimately get moved into their
208 files/ - KERNEL file I/O
209 misc/ - KERNEL registry
211 graphics/ - GDI graphics drivers
212 objects/ - GDI logical objects
214 controls/ - USER built-in widgets
215 windows/ - USER window management
219 IMPLEMENTING NEW API CALLS
220 ==========================
222 This is the simple version, and covers only Win32. Win16 is slightly
223 uglier, because of the Pascal heritage and the segmented memory model.
225 All of the Win32 APIs known to Wine are listed in the .spec file of
226 their corresponding dll. An unimplemented call will look like (from
228 269 stub PolyBezierTo
229 To implement this call, you need to do the following four things.
231 1. Find the appropriate parameters for the call, and add a prototype to
232 the correct header file. In this case, that means [include/wingdi.h],
233 and it might look like
234 BOOL WINAPI PolyBezierTo(HDC, LPCVOID, DWORD);
235 If the function has both an ASCII and a Unicode version, you need to
236 define both and add a #define WINELIB_NAME_AW declaration. See below
237 for discussion of function naming conventions.
239 2. Modify the .spec file to tell Wine that the function has an
240 implementation, what the parameters look like and what Wine function
241 to use for the implementation. In Win32, things are simple--everything
242 is 32-bits. However, the relay code handles pointers and pointers to
243 strings slightly differently, so you should use 'str' and 'wstr' for
244 strings, 'ptr' for other pointer types, and 'long' for everything else.
245 269 stdcall PolyBezierTo(long ptr long) PolyBezierTo
246 The 'PolyBezierTo' at the end of the line is which Wine function to use
247 for the implementation.
249 3. Implement the function as a stub. Once you add the function to the .spec
250 file, you must add the function to the Wine source before it will link.
251 Add a function called 'PolyBezierTo' somewhere. Good things to put
253 o a correct prototype, including the WINAPI
254 o header comments, including full documentation for the function and
255 arguments (see documentation/README.documentation)
256 o A FIXME message and an appropriate return value are good things to
259 /************************************************************
260 * PolyBezierTo (GDI32.269)
262 * Draw many Bezier curves.
266 * Failure: FALSE. Use GetLastError() to find the error cause.
271 BOOL WINAPI PolyBezierTo(HDC hdc, /* [In] Device context to draw to */
272 LPCVOID p, /* [In] Array of POINT structs */
273 DWORD count /* [In] Number of points in p */
276 /* tell the user they've got a substandard implementation */
277 FIXME(gdi, ":(%x,%p,%d): stub\n", hdc, p, count);
279 /* some programs may be able to compensate,
280 * if they know what happened
282 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
283 return FALSE; /* error value */
286 4. Implement and test the rest of the function.
289 IMPLEMENTING A NEW DLL
290 ======================
295 Apart from writing the set of needed .c files, you also need to do the
298 1. Create a directory <MyDll> where to store the implementation of
299 the DLL. This directory has to be put under the dlls/ directory.
300 If the DLL exists under Windows as both 16 and 32 bit DLL, you
301 should have a single directory with both implementations.
303 2. Create the Makefile.in in the ./dlls/<MyDll>/ directory. You can
304 copy an existing Makefile.in from another ./dlls/ subdirectory.
305 You need at least to change the MODULE and C_SRCS macros.
307 3. Add the directory in ./configure.ac (in AC_OUTPUT macro at the end
308 of the file to trigger the Makefile generation)
310 4. Run ./make_dlls in the dlls directory to update Makefile.in in
313 5. You can now regenerate ./configure file (with 'make configure')
314 and the various Makefiles (with 'configure; make depend') (run
315 from the top of Wine's tree).
316 You should now have a Makefile file in ./dlls/<MyDll>/
318 6. Create the .spec file for the DLL exported functions in your
319 directory. Refer to 'Implementation of new API calls' earlier in
320 this document for more information on this part.
322 7. You can now start adding .c files. For the .h files, if they are
323 standard Windows one, put them in include/. If they are linked to
324 *your* implementation of the dll, put them in your newly created
330 If you need to create a new debug channel, just add the
331 WINE_DEFAULT_DEBUG_CHANNEL to your .c file(s), and use them.
332 All the housekeeping will happen automatically.
337 If you also need to add resources to your DLL, then create the .rc
338 file. Add to your ./dlls/<MyDll>/Makefile.in, in the RC_SRCS macro,
339 the list of .rc files to add to the DLL. See dlls/comctl32/ for an
345 If you're building a 16 & 32 bit DLLs pair, then from the 32 bit code
346 you might need to call 16 bit routine. The way to do it to add in the
347 code, fragments like:
348 /* ### Start build ### */
349 extern WORD CALLBACK <PREFIX>_CallTo16_word_wwlll(FARPROC16,WORD,WORD,LONG,LONG,LONG);
350 /* ### stop build ### */
351 Where <PREFIX>_ is an internal prefix for your module. The first
352 parameter is always of type FARPROC16. Then, you can get the regular
353 list of parameters. The _word_wwlll indicates the type of return (long
354 or word) and the size of the parameters (here l=>long, w=>word; which
355 maps to WORD,WORD,LONG,LONG,LONG.
356 You can put several functions between the Start/Stop build pair.
358 You can also read the winebuild manpage for more details on this.
360 Then, add to ./dlls/<MyDll>/Makefile.in a line like:
362 EXTRA_OBJS = $(MODULE).glue.o
364 See dlls/winmm/ for an example of this.
369 NE (Win16) executables consist of multiple segments. The Wine loader
370 loads each segment into a unique location in the Wine processes memory
371 and assigns a selector to that segment. Because of this, it's not
372 possible to exchange addresses freely between 16-bit and 32-bit code.
373 Addresses used by 16-bit code are segmented addresses (16:16), formed
374 by a 16-bit selector and a 16-bit offset. Those used by the Wine code
375 are regular 32-bit linear addresses.
377 There are four ways to obtain a segmented pointer:
378 - Using the MapLS function (recommended).
379 - Allocate a block of memory from the global heap and use
380 WIN16_GlobalLock to get its segmented address.
381 - Declare the argument as 'segptr' instead of 'ptr' in the spec file
382 for a given API function.
384 Once you have a segmented pointer, it must be converted to a linear
385 pointer before you can use it from 32-bit code. This can be done with
386 the MapSL function. The linear pointer can then be used freely with
387 standard Unix functions like memcpy() etc. without worrying about 64k
388 boundaries. Note: there's no easy way to convert back from a linear
389 to a segmented address.
391 In most cases, you don't need to worry about segmented address, as the
392 conversion is made automatically by the callback code and the API
393 functions only see linear addresses. However, in some cases it is
394 necessary to manipulate segmented addresses; the most frequent cases
396 - API functions that return a pointer
397 - lParam of Windows messages that point to a structure
398 - Pointers contained inside structures accessed by 16-bit code.
400 It is usually a good practice to used the type 'SEGPTR' for segmented
401 pointers, instead of something like 'LPSTR' or 'char *'. As SEGPTR is
402 defined as a DWORD, you'll get a compilation warning if you mistakenly
403 use it as a regular 32-bit pointer.
409 Under Windows, data structures are tightly packed, i.e. there is no
410 padding between structure members. On the other hand, by default gcc
411 aligns structure members (e.g. WORDs are on a WORD boundary, etc.).
412 This means that a structure like
414 struct { BYTE x; WORD y; };
416 will take 3 bytes under Windows, but 4 with gcc, because gcc will add a
417 dummy byte between x and y. To have the correct layout for structures
418 used by Windows code, you need to embed the struct within two special
419 #include's which will take care of the packing for you:
421 #include "pshpack1.h"
422 struct { BYTE x; WORD y; };
423 #include "poppack1.h"
425 For alignment on a 2-byte boundary, there is a "pshpack2.h", etc.
427 The use of the WINE_PACKED attribute is obsolete. Please remove these
428 in favour of the above solution.
429 Using WINE_PACKED, you would declare the above structure like this:
431 struct { BYTE x; WORD y WINE_PACKED; };
433 You had to do this every time a structure member is not aligned
434 correctly under Windows (i.e. a WORD not on an even address, or a
435 DWORD on a address that was not a multiple of 4).
438 NAMING CONVENTIONS FOR API FUNCTIONS AND TYPES
439 ==============================================
441 In order to support both Win16 and Win32 APIs within the same source
442 code, the following convention must be used in naming all API
443 functions and types. If the Windows API uses the name 'xxx', the Wine
446 - 'xxx16' for the Win16 version,
447 - 'xxx' for the Win32 version when no ASCII/Unicode strings are
449 - 'xxxA' for the Win32 version with ASCII strings,
450 - 'xxxW' for the Win32 version with Unicode strings.
452 If the function has both ASCII and Unicode version, you should then
453 use the macros WINELIB_NAME_AW(xxx) or DECL_WINELIB_TYPE_AW(xxx)
454 (defined in include/windef.h) to define the correct 'xxx' function
455 or type for Winelib. When compiling Wine itself, 'xxx' is _not_
456 defined, meaning that code inside of Wine must always specify
457 explicitly the ASCII or Unicode version.
459 If 'xxx' is the same in Win16 and Win32, you can simply use the same
460 name as Windows, i.e. just 'xxx'. If 'xxx' is Win16 only, you could
461 use the name as is, but it's preferable to use 'xxx16' to make it
462 clear it is a Win16 function.
466 typedef struct { /* Win32 ASCII data structure */ } WNDCLASSA;
467 typedef struct { /* Win32 Unicode data structure */ } WNDCLASSW;
468 typedef struct { /* Win16 data structure */ } WNDCLASS16;
469 DECL_WINELIB_TYPE_AW(WNDCLASS);
471 ATOM RegisterClass16( WNDCLASS16 * );
472 ATOM RegisterClassA( WNDCLASSA * );
473 ATOM RegisterClassW( WNDCLASSW * );
474 #define RegisterClass WINELIB_NAME_AW(RegisterClass)
476 The Winelib user can then say:
478 WNDCLASS wc = { ... };
479 RegisterClass( &wc );
481 and this will use the correct declaration depending on the definition
482 of the UNICODE symbol.
485 NAMING CONVENTIONS FOR NON-API FUNCTIONS AND TYPES
486 ==================================================
488 Functions and data which are internal to your code (or at least shouldn't be
489 visible to any Winelib or Windows program) should be preceded by
490 an identifier to the module:
494 ENUMPRINTERS_GetDWORDFromRegistryA() (in dlls/winspool/info.c)
495 IAVIFile_fnRelease() (in dlls/avifil32/avifile.c)
496 X11DRV_CreateDC() (in graphics/x11drv/init.c)
498 if you need prototypes for these, there are a few possibilities:
499 - within same source file only:
500 put the prototypes at the top of your file and mark them as prototypes.
501 - within the same module:
502 create a header file within the subdirectory where that module resides,
503 e.g. graphics/ddraw_private.h
504 - from a totally different module, or for use in winelib:
505 you should never do that. Only exported APIs can be called across
512 To display a message only during debugging, you normally write something
520 depending on the seriousness of the problem. (documentation/debugging.sgml
521 explains when it is appropriate to use each of them). You need to declare
522 the debug channel name at the top of the file (after the includes) using
523 the WINE_DEFAULT_DEBUG_CHANNEL macro, like so:
525 WINE_DEFAULT_DEBUG_CHANNEL(win);
527 If your debugging code is more complex than just printf, you can use
530 TRACE_ON(xxx), WARN_ON(xxx), ERR_ON(xxx) and FIXME_ON(xxx)
532 to test if the given channel is enabled. Thus, you can write:
534 if (TRACE_ON(win)) DumpSomeStructure(&str);
536 Don't worry about the inefficiency of the test. If it is permanently
537 disabled (that is TRACE_ON(win) is 0 at compile time), the compiler will
538 eliminate the dead code.
540 For more info about debugging messages, read:
542 http://www.winehq.org/site/docs/wine-devel/debugging
548 1. There is a FREE online version of the MSDN library (including
549 documentation for the Win32 API) on http://msdn.microsoft.com/
550 or http://www.msdn.com/
552 2. Windows apilist: http://www.mentalis.org/apilist/apilist.php
554 3. http://www.sonic.net/~undoc/bookstore.html
556 4. In 1993 Dr. Dobbs Journal published a column called "Undocumented Corner".
558 5. www.geocities.com/SiliconValley/4942/