msi: Fix handling of the no-op identifier in the Directory table.
[wine/multimedia.git] / DEVELOPERS-HINTS
blobc32993602958ebc84b5ca03297d9a704c106ddc5
1 This document should help new developers get started. Like all of Wine, it
2 is a work in progress.
5 SOURCE TREE STRUCTURE
6 =====================
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.
14 DLLs (under dlls/):
15 -------------------
17         activeds/               - Active Directory Service Interface
18         advapi32/               - Crypto, systeminfo, security, eventlogging
19         advpack/                - Reads and verifies .INF files
20         amstream/               - MultiMedia Streams
21         atl/                    - Active Template Library
22         avicap32/               - AVI capture window class
23         avifil32/               - COM object to play AVI files
24         cabinet/                - Cabinet file interface
25         capi2032/               - Wrapper library for CAPI4Linux access
26         cards/                  - Card graphics
27         cfgmgr32/               - Config manager
28         comcat/                 - Component category manager
29         comctl32/               - Common controls
30         comdlg32/               - Common dialog boxes (both 16 & 32 bit)
31         crtdll/                 - Old C runtime library
32         crypt32/                - Cryptography
33         cryptdll/               - Cryptography Manager
34         ctl3d32/                - 3D Effects for Common GUI Components
35         d3d8/                   - Direct3D (3D graphics)
36         d3d9/                   - Direct3D (3D graphics)
37         d3dim/                  - Direct3D Immediate Mode
38         d3drm/                  - Direct3D Retained Mode
39         d3dx8/                  - Direct3D (3D graphics)
40         d3dxof/                 - DirectX Files Functions
41         dbghelp/                - Engine for symbol and module enumeration
42         dciman32/               - DCI Manager (graphics)
43         ddraw/                  - DirectDraw (graphics)
44         devenum/                - Device enumeration (part of DirectShow)
45         dinput/                 - DirectInput (device input)
46         dinput8/                - DirectInput (device input)
47         dmband/                 - DirectMusic Band
48         dmcompos/               - DirectMusic Composer
49         dmime/                  - DirectMusic Interactive Engine
50         dmloader/               - DirectMusic Loader
51         dmscript/               - DirectMusic Scripting
52         dmstyle/                - DirectMusic Style Engine
53         dmsynth/                - DirectMusic Software Synthesizer
54         dmusic/                 - DirectMusic Core Services
55         dmusic32/               - DirectMusic Legacy Port
56         dnsapi/                 - DNS support
57         dplay/                  - DirectPlay (networking)
58         dplayx/                 - DirectPlay (networking)
59         dpnet/                  - DirectPlay (networking)
60         dpnhpast/               - DirectPlay NAT Helper PAST
61         dsound/                 - DirectSound (audio)
62         dswave/                 - DirectMusic Wave
63         dxdiagn/                - DirectX Diagnostic Tool 
64         gdi/                    - GDI (graphics)
65         glu32/                  - OpenGL Utility library (graphics)
66         glut32/                 - OpenGL Utility Toolkit
67         gphoto2.ds/             - Contains libgphoto2 based TWAIN datasource driver
68         hhctrl.ocx/             - HHCTRL OCX implementation
69         iccvid/                 - Radius Cinepak Video Decoder
70         icmp/                   - ICMP protocol (networking)
71         ifsmgr.vxd/             - IFSMGR VxD implementation
72         imaadp32.acm/           - IMA ADPCM Audio Codec
73         imagehlp/               - PE (Portable Executable) Image Helper lib
74         imm32/                  - Input Method Manager
75         iphlpapi/               - IP Helper API
76         itss/                   - Infotech Structured Storage (HTML Help)
77         kernel/                 - The Windows kernel
78         lz32/                   - Lempel-Ziv compression/decompression
79         mapi32/                 - Mail interface
80         mciavi32/               - MCI video driver
81         mcicda/                 - MCI audio CD driver
82         mciseq/                 - MCI MIDI driver
83         mciwave/                - MCI wave driver
84         midimap/                - MIDI mapper
85         mlang/                  - Multi Language Support
86         mmdevldr.vxd/           - MMDEVLDR VxD implementation
87         monodebg.vxd/           - MONODEBG VxD implementation
88         mpr/                    - Multi-Protocol Router (networking)
89         mprapi/                 - Multi-Protocol Router Administration
90         msacm32/                - Audio Compression Manager (multimedia)
91         msacm32.drv/            - Audio mapper
92         msadp32.acm/            - MS ADPCM Audio Codec
93         mscms/                  - Color Management System
94         msdmo/                  - DirectX Media Objects
95         msftedit/               - Rich text editing control (Version 4.1)
96         msg711.acm/             - MS G711 Audio Codec (includes A-Law & MU-Law)
97         mshtml/                 - MS HTML component
98         msi/                    - Microsoft Installer
99         msimg32/                - Gradient and transparency (graphics)
100         msisys.ocx/             - System information
101         msnet32/                - Network interface
102         msrle32/                - Video codecs
103         msvcrt/                 - C runtime library 
104         msvcrt20/               - C runtime library version 2.0
105         msvcrt40/               - C runtime library version 4.0
106         msvcrtd/                - C runtime library debugging
107         msvfw32/                - 16 bit video manager
108         msvidc32/               - Microsoft Video-1 Decoder
109         mswsock/                - Misc networking
110         msxml3/                 - MSXML Class Factory
111         netapi32/               - Network interface
112         newdev/                 - New Hardware Device Library
113         ntdll/                  - NT implementation of kernel calls
114         ntdsapi/                - NT Directory Service Provider
115         objsel/                 - Object Picker Dialog
116         odbc32/                 - Open DataBase Connectivity driver manager
117         odbccp32/               - Open DataBase Connectivity driver installer
118         ole32/                  - 32 bit OLE 2.0 libraries
119         oleacc/                 - OLE accessibility support
120         oleaut32/               - 32 bit OLE 2.0 automation
121         olecli32/               - 16 bit OLE client
122         oledlg/                 - OLE 2.0 user interface support
123         olepro32/               - 32 bit OLE 2.0 automation
124         olesvr32/               - 16 bit OLE server
125         opengl32/               - OpenGL implementation (graphics)
126         powrprof/               - Power Management and Profiling
127         psapi/                  - Process Status interface
128         qcap/                   - DirectShow runtime
129         quartz/                 - DirectShow runtime
130         rasapi32/               - Remote Access Server interface
131         riched20/               - Rich text editing control (Version 2.0 and 3.0)
132         riched32/               - Rich text editing control
133         rpcrt4/                 - Remote Procedure Call runtime
134         rsabase/                - RSA encryption
135         rsaenh/                 - Crypto API (DES, 3DES, RSA, etc.)
136         sane.ds/                - Contains sane based TWAIN datasource driver
137         secur32/                - Contains Windows Security functions
138         security/               - Security Support Provider Interface
139         sensapi/                - System Event Notification Service
140         serialui/               - Serial port property pages
141         setupapi/               - Setup interface
142         sfc/                    - System File Checker (Windows File Protection)
143         shdocvw/                - Shell document object and control
144         shell32/                - COM object implementing shell views
145         shfolder/               - Shell folder service
146         shlwapi/                - Shell Light-Weight interface
147         snmpapi/                - SNMP protocol interface (networking)
148         spoolss/                - Spooler Subsystem Library ("spooler" - Service)
149         stdole2.tlb/            - OLE Automation typelib
150         stdole32.tlb/           - Standard OLE typelib
151         sti/                    - Still Image service
152         tapi32/                 - Telephone interface
153         twain_32/               - TWAIN Imaging device communications
154         unicows/                - Unicows replacement (Unicode layer for Win9x)
155         url/                    - Internet shortcut shell extension
156         urlmon/                 - URL Moniker allows binding to a URL
157         user/                   - Window management, standard controls, etc.
158         usp10/                  - Uniscribe Script Processor
159         uxtheme/                - Theme library
160         vdhcp.vxd/              - VDHCP VxD implementation
161         vdmdbg/                 - Virtual DOS machine debug library
162         version/                - File installation library
163         vmm.vxd/                - VMM VxD implementation
164         vnbt.vxd/               - VNBT VxD implementation
165         vnetbios.vxd/           - VNETBIOS VxD implementation
166         vtdapi.vxd/             - VTDAPI VxD implementation
167         vwin32.vxd/             - VWIN32 VxD implementation
168         win32skrnl/             - 32-bit function access for 16-bit systems
169         wined3d/                - Wine internal Direct3D helper
170         winedos/                - DOS features and BIOS calls (Wine specific)
171         winemp3.acm/            - Mpeg Layer 3 Audio Codec
172         wineps.drv/             - Postscript driver (Wine specific)
173         wininet/                - Internet extensions
174         winmm/                  - Multimedia (16 & 32 bit)
175         winmm/joystick/         - Joystick driver
176         winmm/winealsa/         - ALSA audio driver
177         winmm/winearts/         - aRts audio driver
178         winmm/wineaudioio/      - audioio audio driver
179         winmm/winejack/         - JACK audio server driver
180         winmm/winenas/          - NAS audio driver
181         winmm/wineoss/          - OSS audio driver
182         winnls32/               - National Language Support
183         winspool.drv/           - Printing & Print Spooler
184         wintab32/               - Tablet device interface
185         wintrust/               - Trust verification interface
186         wldap32/                - LDAP support
187         wnaspi32/               - 16 bit Advanced SCSI Peripheral Interface
188         wow32/                  - WOW subsystem
189         ws2_32/                 - Sockets 2.0 (networking)
190         wsock32/                - Sockets 1.1 (networking)
191         wtsapi32/               - Terminal Services
192         x11drv/                 - X11 display driver (Wine specific)
194 Winelib programs (under programs/):
195 -----------------------------------
197         clock/                  - Graphical clock
198         cmdlgtst/               - Common dialog tests
199         control/                - Control panel
200         eject/                  - Unmount and eject removable Media
201         expand/                 - Decompress Lempel-Ziv compressed archive
202         explorer/               - Desktop/Systray/HAL-Manager, Winefile-wrapper
203         hh/                     - HTML Help viewer
204         icinfo/                 - List/Configure installed Video Compressors
205         iexplore/               - Internet Explorer replacement 
206         msiexec/                - Microsoft Installer frontend
207         notepad/                - Notepad replacement 
208         progman/                - Program manager
209         regedit/                - Registry editor
210         regsvr32/               - Register COM server
211         rpcss/                  - RPC services
212         rundll32/               - Execute DLL functions directly
213         start/                  - Replacement for start.exe
214         taskmgr/                - Manage running Windows/Winelib applications
215         uninstaller/            - Remove installed programs
216         view/                   - Metafile viewer
217         wcmd/                   - Command line interface
218         wineboot/               - Wine bootstrap process
219         winebrowser/            - Frontend for Webbrowsers on the Host
220         winecfg/                - Wine configuration utility
221         wineconsole/            - Console
222         winedbg/                - Debugger
223         winefile/               - File manager
224         winemenubuilder/        - Helper program for building Unix menu entries
225         winemine/               - Mine game
226         winepath/               - Translate between Wine and Unix paths
227         winetest/               - Wine testing shell
228         winevdm/                - Wine virtual DOS machine
229         winhelp/                - Help viewer
230         winver/                 - Windows Version Program
231         wordpad/                - Wordpad replacement skeleton
234 Support programs, libraries, etc:
235 ---------------------------------
237         dlls/dxerr8/            - DirectX 8 error import lib
238         dlls/dxerr9/            - DirectX 9 error import lib
239         dlls/dxguid/            - DirectX UUID import lib
240         dlls/strmiids/          - Exports class CLSIDs and interface IIDs
241         dlls/uuid/              - Windows-compatible UUID import lib
242         documentation/          - some documentation
243         include/                - Windows standard includes
244         include/msvcrt/         - MSVC compatible libc headers
245         include/wine/           - Wine specific headers
246         libs/                   - the Wine libraries
247         libs/port/              - portability library
248         libs/unicode/           - Unicode support shared
249         libs/wine/              - Wine bootstrap library
250         libs/wpp/               - C preprocessor
251         loader/                 - the main Wine loader
252         server/                 - the Wine server
253         tools/                  - various tools used to build/check Wine
254         tools/widl/             - the IDL compiler
255         tools/winapi/   - A Win32 API checker
256         tools/winebuild/        - Wine build tool
257         tools/winedump/         - a .DLL dump utility
258         tools/winegcc/          - a MinGW command line compatible gcc wrapper
259         tools/wmc/              - the message compiler
260         tools/wrc/              - the resource compiler
264 IMPLEMENTING NEW API CALLS
265 ==========================
267 This is the simple version, and covers only Win32. Win16 is slightly
268 uglier, because of the Pascal heritage and the segmented memory model.
270 All of the Win32 APIs known to Wine are listed in the .spec file of
271 their corresponding dll. An unimplemented call will look like (from
272 gdi32.spec)
273   269 stub PolyBezierTo
274 To implement this call, you need to do the following four things.
276 1. Find the appropriate parameters for the call, and add a prototype to
277 the correct header file. In this case, that means [include/wingdi.h],
278 and it might look like
279   BOOL WINAPI PolyBezierTo(HDC, LPCVOID, DWORD);
280 If the function has both an ASCII and a Unicode version, you need to
281 define both and add a #define WINELIB_NAME_AW declaration. See below
282 for discussion of function naming conventions.
283   
284 2. Modify the .spec file to tell Wine that the function has an
285 implementation, what the parameters look like and what Wine function
286 to use for the implementation. In Win32, things are simple--everything
287 is 32-bits. However, the relay code handles pointers and pointers to
288 strings slightly differently, so you should use 'str' and 'wstr' for
289 strings, 'ptr' for other pointer types, and 'long' for everything else.
290   269 stdcall PolyBezierTo(long ptr long) PolyBezierTo
291 The 'PolyBezierTo' at the end of the line is which Wine function to use
292 for the implementation.
294 3. Implement the function as a stub. Once you add the function to the .spec
295 file, you must add the function to the Wine source before it will link.
296 Add a function called 'PolyBezierTo' somewhere. Good things to put
297 into a stub:
298   o a correct prototype, including the WINAPI
299   o header comments, including full documentation for the function and
300     arguments (see documentation/README.documentation)
301   o A FIXME message and an appropriate return value are good things to
302     put in a stub.
304   /************************************************************
305    *                    PolyBezierTo   (GDI32.269)  
306    *  
307    * Draw many Bezier curves.
308    *
309    * PARAMS
310    *   hdc   [I] Device context to draw to
311    *   p     [I] Array of POINT structs
312    *   count [I] Number of points in p
313    *
314    * RETURNS
315    *   Success: Non-zero.
316    *   Failure: FALSE. Use GetLastError() to find the error cause.
317    *
318    * BUGS
319    *   Unimplemented
320    */
321    BOOL WINAPI PolyBezierTo(HDC hdc, LPCVOID p, DWORD count) 
322    {
323        /* tell the user they've got a substandard implementation */
324        FIXME("(%x,%p,%d): stub\n", hdc, p, count);
326        /* some programs may be able to compensate, 
327         * if they know what happened 
328         */
329        SetLastError(ERROR_CALL_NOT_IMPLEMENTED);  
330        return FALSE;    /* error value */
331    }
333 4. Implement and test the rest of the function.
336 IMPLEMENTING A NEW DLL
337 ======================
339 Generic directions
340 ------------------
342 Apart from writing the set of needed .c files, you also need to do the 
343 following:
345 1.  Create a directory <MyDll> where to store the implementation of
346     the DLL. This directory has to be put under the dlls/ directory.
347     If the DLL exists under Windows as both 16 and 32 bit DLL, you
348     should have a single directory with both implementations.
350 2.  Create the Makefile.in in the ./dlls/<MyDll>/ directory. You can
351     copy an existing Makefile.in from another ./dlls/ subdirectory.
352     You need at least to change the MODULE and C_SRCS macros. 
354 3.  Add the directory in ./configure.ac (in AC_OUTPUT macro at the end
355     of the file to trigger the Makefile generation)
357 4.  Run ./make_dlls in the dlls directory to update Makefile.in in
358     that directory.
360 5.  You can now regenerate ./configure file (with 'autoconf')
361     and the various Makefiles (with 'configure; make depend') (run
362     from the top of Wine's tree).
363     You should now have a Makefile file in ./dlls/<MyDll>/
365 6.  Create the .spec file for the DLL exported functions in your
366     directory. Refer to 'Implementation of new API calls' earlier in
367     this document for more information on this part.
369 7.  You can now start adding .c files. For the .h files, if they are
370     standard Windows one, put them in include/. If they are linked to
371     *your* implementation of the dll, put them in your newly created
372     directory.
374 Debug channels
375 --------------
377 If you need to create a new debug channel, just add the
378 WINE_DEFAULT_DEBUG_CHANNEL to your .c file(s), and use them. 
379 All the housekeeping will happen automatically.
381 Resources
382 ---------
384 If you also need to add resources to your DLL, then create the .rc
385 file. Add to your ./dlls/<MyDll>/Makefile.in, in the RC_SRCS macro,
386 the list of .rc files to add to the DLL. See dlls/comctl32/ for an
387 example of this.
389 Thunking
390 --------
392 If you're building a 16 & 32 bit DLLs pair, then from the 32 bit code
393 you might need to call 16 bit routine. The way to do it to add in the
394 code, fragments like:
395 /* ### Start build ### */
396 extern WORD CALLBACK <PREFIX>_CallTo16_word_wwlll(FARPROC16,WORD,WORD,LONG,LONG,LONG);
397 /* ### stop build ### */
398 Where <PREFIX>_ is an internal prefix for your module. The first
399 parameter is always of type FARPROC16. Then, you can get the regular
400 list of parameters. The _word_wwlll indicates the type of return (long
401 or word) and the size of the parameters (here l=>long, w=>word; which
402 maps to WORD,WORD,LONG,LONG,LONG.
403 You can put several functions between the Start/Stop build pair.
405 You can also read the winebuild manpage for more details on this.
407 Then, add to ./dlls/<MyDll>/Makefile.in a line like:
409 EXTRA_OBJS = $(MODULE).glue.o
411 See dlls/winmm/ for an example of this.
413 MEMORY AND SEGMENTS
414 ===================
416 NE (Win16) executables consist of multiple segments.  The Wine loader
417 loads each segment into a unique location in the Wine processes memory
418 and assigns a selector to that segment.  Because of this, it's not
419 possible to exchange addresses freely between 16-bit and 32-bit code.
420 Addresses used by 16-bit code are segmented addresses (16:16), formed
421 by a 16-bit selector and a 16-bit offset.  Those used by the Wine code
422 are regular 32-bit linear addresses.
424 There are four ways to obtain a segmented pointer:
425   - Using the MapLS function (recommended).
426   - Allocate a block of memory from the global heap and use
427     WIN16_GlobalLock to get its segmented address.
428   - Declare the argument as 'segptr' instead of 'ptr' in the spec file
429     for a given API function.
431 Once you have a segmented pointer, it must be converted to a linear
432 pointer before you can use it from 32-bit code.  This can be done with
433 the MapSL function.  The linear pointer can then be used freely with
434 standard Unix functions like memcpy() etc. without worrying about 64k
435 boundaries.  Note: there's no easy way to convert back from a linear
436 to a segmented address.
438 In most cases, you don't need to worry about segmented address, as the
439 conversion is made automatically by the callback code and the API
440 functions only see linear addresses. However, in some cases it is
441 necessary to manipulate segmented addresses; the most frequent cases
442 are:
443   - API functions that return a pointer
444   - lParam of Windows messages that point to a structure
445   - Pointers contained inside structures accessed by 16-bit code.
447 It is usually a good practice to used the type 'SEGPTR' for segmented
448 pointers, instead of something like 'LPSTR' or 'char *'.  As SEGPTR is
449 defined as a DWORD, you'll get a compilation warning if you mistakenly
450 use it as a regular 32-bit pointer.
453 STRUCTURE PACKING
454 =================
456 Under Windows, data structures are tightly packed, i.e. there is no
457 padding between structure members. On the other hand, by default gcc
458 aligns structure members (e.g. WORDs are on a WORD boundary, etc.).
459 This means that a structure like
461 struct { BYTE x; WORD y; };
463 will take 3 bytes under Windows, but 4 with gcc, because gcc will add a
464 dummy byte between x and y. To have the correct layout for structures
465 used by Windows code, you need to embed the struct within two special
466 #include's which will take care of the packing for you:
468 #include "pshpack1.h"
469 struct { BYTE x; WORD y; };
470 #include "poppack1.h"
472 For alignment on a 2-byte boundary, there is a "pshpack2.h", etc.
475 NAMING CONVENTIONS FOR API FUNCTIONS AND TYPES
476 ==============================================
478 In order to support both Win16 and Win32 APIs within the same source
479 code, the following convention must be used in naming all API
480 functions and types. If the Windows API uses the name 'xxx', the Wine
481 code must use:
483  - 'xxx16' for the Win16 version,
484  - 'xxx'   for the Win32 version when no strings are involved,
485  - 'xxxA'  for the Win32 version with ASCII strings,
486  - 'xxxW'  for the Win32 version with Unicode strings.
488 If the function has both ASCII and Unicode version, you should then
489 use the macros WINELIB_NAME_AW(xxx) or DECL_WINELIB_TYPE_AW(xxx)
490 (defined in include/windef.h) to define the correct 'xxx' function
491 or type for Winelib. When compiling Wine itself, 'xxx' is _not_
492 defined, meaning that code inside of Wine must always specify
493 explicitly the ASCII or Unicode version.
495 If 'xxx' is the same in Win16 and Win32, you can simply use the same
496 name as Windows, i.e. just 'xxx'.  If 'xxx' is Win16 only, you could
497 use the name as is, but it's preferable to use 'xxx16' to make it
498 clear it is a Win16 function.
500 Examples:
502 typedef struct { /* Win32 ASCII data structure */ } WNDCLASSA;
503 typedef struct { /* Win32 Unicode data structure */ } WNDCLASSW;
504 typedef struct { /* Win16 data structure */ } WNDCLASS16;
505 DECL_WINELIB_TYPE_AW(WNDCLASS);
507 ATOM RegisterClass16( WNDCLASS16 * );
508 ATOM RegisterClassA( WNDCLASSA * );
509 ATOM RegisterClassW( WNDCLASSW * );
510 #define RegisterClass WINELIB_NAME_AW(RegisterClass)
512 The Winelib user can then say:
514     WNDCLASS wc = { ... };
515     RegisterClass( &wc );
517 and this will use the correct declaration depending on the definition
518 of the UNICODE symbol.
521 DEBUG MESSAGES
522 ==============
524 To display a message only during debugging, you normally write something
525 like this:
527         TRACE("abc...");  or
528         FIXME("abc...");  or
529         WARN("abc...");   or
530         ERR("abc...");
532 depending on the seriousness of the problem. (documentation/debugging.sgml
533 explains when it is appropriate to use each of them). You need to declare
534 the debug channel name at the top of the file (after the includes) using
535 the WINE_DEFAULT_DEBUG_CHANNEL macro, like so:
537         WINE_DEFAULT_DEBUG_CHANNEL(win);
539 If your debugging code is more complex than just printf, you can use 
540 the macros:
542         TRACE_ON(xxx), WARN_ON(xxx), ERR_ON(xxx) and FIXME_ON(xxx) 
544 to test if the given channel is enabled. Thus, you can write:
546         if (TRACE_ON(win)) DumpSomeStructure(&str);
548 Don't worry about the inefficiency of the test. If it is permanently 
549 disabled (that is TRACE_ON(win) is 0 at compile time), the compiler will 
550 eliminate the dead code.
552 For more info about debugging messages, read:
554 http://www.winehq.org/site/docs/wine-devel/debugging
557 MORE INFO
558 =========
560 1. There is a FREE online version of the MSDN library (including
561    documentation for the Win32 API) on http://msdn.microsoft.com/
562    or http://www.msdn.com/
564 2. Windows apilist:  http://www.mentalis.org/apilist/apilist.php
566 3. http://www.sonic.net/~undoc/bookstore.html
568 4. In 1993 Dr. Dobbs Journal published a column called "Undocumented Corner".
570 5. www.geocities.com/SiliconValley/4942/