This document should help new developers get started.
Contents
Source tree structure
The Wine source tree is loosely based on the original Windows modules. Most of the source is concerned with implementing the Wine API, although there are also various tools, documentation, sample Winelib code, and code specific to the binary loader. Note that several of the libraries listed here are "stubbed out", meaning they still need to be implemented.
Dlls (under dlls/):
|
|
activeds/ |
Active Directory Service Interface |
actxprxy/ |
ActiveX Interface Marshaling |
advapi32/ |
Crypto, systeminfo, security, eventlogging |
advpack/ |
Reads and verifies .INF files |
amstream/ |
MultiMedia Streams |
atl/ |
Active Template Library |
avicap32/ |
AVI capture window class |
avifil32/ |
COM object to play AVI files |
browseui/ |
Internet Explorer / Windows Explorer standard UI |
cabinet/ |
Cabinet file interface |
capi2032/ |
Wrapper library for CAPI4Linux access |
cards/ |
Card graphics |
cfgmgr32/ |
Config manager |
clusapi/ |
Cluster API |
comcat/ |
Component category manager |
comctl32/ |
Common controls |
comdlg32/ |
Common dialog boxes (both 16 & 32 bit) |
compstui/ |
Common Property Sheet User Interface (Printer Dialogs) |
credui/ |
Credentials User Interface |
crtdll/ |
Old C runtime library |
crypt32/ |
Cryptography |
cryptdlg/ |
Common Certificate Dialogs (Cryptography) |
cryptdll/ |
Cryptography Manager |
ctapi32/ |
Wrapper library for Chipcard Terminal access |
ctl3d32/ |
3D Effects for Common GUI Components |
d3d10/ |
Direct3D (3D graphics) |
d3d8/ |
Direct3D (3D graphics) |
d3d9/ |
Direct3D (3D graphics) |
d3dim/ |
Direct3D Immediate Mode |
d3drm/ |
Direct3D Retained Mode |
d3dx8/ |
Direct3D (3D graphics) |
d3dx9_xx/ |
Direct3D (3D graphics, 12 versions from 24 upto 36) |
d3dxof/ |
DirectX Files Functions |
dbghelp/ |
Engine for symbol and module enumeration |
dciman32/ |
DCI Manager (graphics) |
ddraw/ |
DirectDraw (graphics) |
ddrawex/ |
DirectDraw(graphics) |
devenum/ |
Device enumeration (part of DirectShow) |
dinput/ |
DirectInput (device input) |
dinput8/ |
DirectInput (device input) |
dmband/ |
DirectMusic Band |
dmcompos/ |
DirectMusic Composer |
dmime/ |
DirectMusic Interactive Engine |
dmloader/ |
DirectMusic Loader |
dmscript/ |
DirectMusic Scripting |
dmstyle/ |
DirectMusic Style Engine |
dmsynth/ |
DirectMusic Software Synthesizer |
dmusic/ |
DirectMusic Core Services |
dmusic32/ |
DirectMusic Legacy Port |
dnsapi/ |
DNS support |
dplay/ |
DirectPlay (networking) |
dplayx/ |
DirectPlay (networking) |
dpnaddr/ |
DirectPlay (networking) |
dpnet/ |
DirectPlay (networking) |
dpnhpast/ |
DirectPlay NAT Helper PAST |
dpnlobby/ |
DirectPlay 8 lobby |
dsound/ |
DirectSound (audio) |
dssenh/ |
Enhanced DSS and Diffie-Hellman Crypt. Provider |
dswave/ |
DirectMusic Wave |
dwmapi/ |
Desktop Window Manager |
dxdiagn/ |
DirectX Diagnostic Tool |
faultrep/ |
Fault report handling |
gdi32/ |
GDI (graphics device interface) |
glu32/ |
OpenGL Utility library (graphics) |
glut32/ |
OpenGL Utility Toolkit (removed in wine 0.9.27) |
gphoto2.ds/ |
Contains libgphoto2 based TWAIN datasource driver |
gpkcsp/ |
Gemplus (gemalto) Crypt. Service Provider |
hal/ |
Hardware Abstraction Layer replacement |
hhctrl.ocx/ |
HHCTRL OCX implementation |
hid/ |
Hid User Library (Human Input Devices) |
hlink/ |
Microsoft Hyperlink Library |
hnetcfg/ |
Microsoft Firewall Manager |
iccvid/ |
Radius Cinepak Video Decoder |
icmp/ |
ICMP protocol (networking) |
ifsmgr.vxd/ |
IFSMGR VxD implementation |
imaadp32.acm/ |
IMA ADPCM Audio Codec |
imagehlp/ |
PE (Portable Executable) Image Helper lib |
imm32/ |
Input Method Manager |
inetcomm/ |
Internet Messaging APIs |
infosoft/ |
Wordbreaker and stemmer |
initpki/ |
PKI Installation and Setup |
inkobj/ |
Tablet PC functions |
inseng/ |
Install engine |
iphlpapi/ |
IP Helper API |
itircl/ |
Infotech IR Local (HTML Help 1.x) |
itss/ |
Infotech Structured Storage (HTML Help 1.x) |
kernel32/ |
The Windows kernel |
localspl/ |
Local Print Monitor (Printing) |
localui/ |
Local Print Monitor User Interface (Printing) |
lz32/ |
Lempel-Ziv compression/ decompression |
mapi32/ |
Mail interface |
mciavi32/ |
MCI video driver |
mcicda/ |
MCI audio CD driver |
mciseq/ |
MCI MIDI driver |
mciwave/ |
MCI wave driver |
midimap/ |
MIDI mapper |
mlang/ |
Multi Language Support |
mmdevldr.vxd/ |
MMDEVLDR VxD implementation |
monodebg.vxd/ |
MONODEBG VxD implementation |
mountmgr.sys// |
Mountpoint Manager service |
mpr/ |
Multi-Protocol Router (networking) |
mprapi/ |
Multi-Protocol Router Administration |
msacm32/ |
Audio Compression Manager (multimedia) |
msacm32.drv/ |
Audio mapper |
msadp32.acm/ |
MS ADPCM Audio Codec |
mscat/ |
Backend for the MakeCat command-line tool |
mscms/ |
Color Management System |
msdmo/ |
DirectX Media Objects |
msftedit/ |
Rich text editing control (Version 4.1) |
msg711.acm/ |
MS G711 Audio Codec (includes A-Law & MU-Law) |
mshtml/ |
MS HTML component |
mshtml.tlb/ |
MS HTML typelib |
msi/ |
Microsoft Installer |
msimg32/ |
Gradient and transparency (graphics) |
msimtf/ |
Active IMM / IME Server DLL |
msisys.ocx/ |
System information |
msnet32/ |
Network interface |
msrle32/ |
Video codecs |
mssip32/ |
Microsoft Trust Subject Package |
msvcirt/ |
C++ runtime library |
msvcr71/ |
C runtime library 7.1 |
msvcrt/ |
C runtime library |
msvcrt20/ |
C runtime library version 2.0 |
msvcrt40/ |
C runtime library version 4.0 |
msvcrtd/ |
C runtime library debugging |
msvfw32/ |
16 bit video manager |
msvidc32/ |
Microsoft Video-1 Decoder |
mswsock/ |
Misc networking |
msxml3/ |
MSXML Class Factory |
netapi32/ |
Network interface |
newdev/ |
New Hardware Device Library |
ntdll/ |
NT implementation of kernel calls |
ntdsapi/ |
NT Directory Service Provider |
ntoskrnl.exe/ |
NT Kernelmode-API replacement |
objsel/ |
Object Picker Dialog |
odbc32/ |
Open DataBase Connectivity driver manager |
odbccp32/ |
Open DataBase Connectivity driver installer |
ole32/ |
32 bit OLE 2.0 libraries |
oleacc/ |
OLE accessibility support |
oleaut32/ |
32 bit OLE 2.0 automation |
olecli32/ |
16 bit OLE client |
oledlg/ |
OLE 2.0 user interface support |
olepro32/ |
32 bit OLE 2.0 automation |
olesvr32/ |
16 bit OLE server |
olethk32/ |
16 bit and 32 bit OLE Thunk library |
opengl32/ |
OpenGL implementation (graphics) |
powrprof/ |
Power Management and Profiling |
printui/ |
Printer User Interface |
propsys/ |
Office Document Property Handler |
psapi/ |
Process Status interface |
qcap/ |
DirectShow runtime |
qedit/ |
DirectShow Editing Services |
qmgr/ |
Background Intelligent Transfer Service (BITS) interface |
quartz/ |
DirectShow runtime |
query/ |
Content Index Utility |
rasapi32/ |
Remote Access Server interface |
riched20/ |
Rich text editing control (Version 2.0 and 3.0) |
riched32/ |
Rich text editing control |
rpcrt4/ |
Remote Procedure Call runtime |
rsabase/ |
RSA encryption |
rsaenh/ |
Crypto API (DES, 3DES, RSA, etc.) |
sane.ds/ |
Contains sane based TWAIN datasource driver |
sccbase/ |
Crypt. Service Provider for Infinion SICRYPT Base Smart Cards |
schannel/ |
TSL and SSL Security Provider Interface |
secur32/ |
Secure Service Provider Interface |
security/ |
Secure Service Provider Interface (old DLL name) |
sensapi/ |
System Event Notification Service |
serialui/ |
Serial port property pages |
setupapi/ |
Setup interface |
sfc/ |
System File Checker (Windows File Protection) |
sfc_os/ |
System File Checker (Windows File Protection) |
shdoclc/ |
Shell document resources |
shdocvw/ |
Shell document object and control |
shell32/ |
COM object implementing shell views |
shfolder/ |
Shell folder service |
shlwapi/ |
Shell Light-Weight interface |
slbcsp/ |
Crypt. Service Provider for Schlumberger Smart Cards |
slc/ |
Software Licensing Client DLL |
snmpapi/ |
SNMP protocol interface (networking) |
softpub/ |
Trust Policy Provider |
spoolss/ |
Spooler Subsystem Library ("spooler" - Service) |
stdole2.tlb/ |
OLE Automation typelib |
stdole32.tlb/ |
Standard OLE typelib |
sti/ |
Still Image service |
tapi32/ |
Telephone interface |
twain_32/ |
TWAIN Imaging device communications |
unicows/ |
Unicows replacement (Unicode layer for Win9x) |
url/ |
Internet shortcut shell extension |
urlmon/ |
URL Moniker allows binding to a URL |
user32/ |
Window management, standard controls, etc. |
userenv/ |
User - Environment and Policy Management |
usp10/ |
Uniscribe Script Processor |
uxtheme/ |
Theme library |
vdhcp.vxd/ |
VDHCP VxD implementation |
vdmdbg/ |
Virtual DOS machine debug library |
version/ |
File installation library |
vmm.vxd/ |
VMM VxD implementation |
vnbt.vxd/ |
VNBT VxD implementation |
vnetbios.vxd/ |
VNETBIOS VxD implementation |
vtdapi.vxd/ |
VTDAPI VxD implementation |
vwin32.vxd/ |
VWIN32 VxD implementation |
win32skrnl/ |
32-bit function access for 16-bit systems |
winealsa.drv/ |
ALSA audio driver |
wineaudioio.drv/ |
audioio audio driver |
winecoreaudio.drv/ |
CoreAudio audio driver (MacOS) |
winecrt0/ |
crt0 library |
wined3d/ |
Wine internal Direct3D helper |
winedos/ |
DOS features and BIOS calls (Wine specific) |
wineesd.drv/ |
Esound audio driver |
winejack.drv/ |
JACK audio server driver |
winejoystick.drv/ |
Joystick driver |
winemp3.acm/ |
Mpeg Layer 3 Audio Codec |
winenas.drv/ |
NAS audio driver |
wineoss.drv/ |
OSS audio driver |
wineps.drv/ |
Postscript printer driver (Wine specific) |
winex11.drv/ |
X11 display driver (Wine specific) |
winhttp/ |
HTTP Services |
wininet/ |
Internet extensions |
winmm/ |
Multimedia (16 & 32 bit) |
winnls32/ |
National Language Support |
winscard/ |
Smart Card API |
winspool.drv/ |
Printing & Print Spooler |
wintab32/ |
Tablet device interface |
wintrust/ |
Trust verification interface |
wldap32/ |
LDAP support |
wmi/ |
Windows Management Instrumentation |
wnaspi32/ |
16 bit Advanced SCSI Peripheral Interface |
wow32/ |
WOW subsystem |
ws2_32/ |
Sockets 2.0 (networking) |
wsock32/ |
Sockets 1.1 (networking) |
wtsapi32/ |
Terminal Services |
Winelib programs (under programs/):
|
||
clock/ |
Graphical clock |
|
cmd/ |
Command line interface |
|
cmdlgtst/ |
Common dialog tests |
|
control/ |
Control panel |
|
eject/ |
Unmount and eject removable Media |
|
expand/ |
Decompress Lempel-Ziv compressed archive |
|
explorer/ |
Desktop/Systray/HAL-Manager, Winefile-wrapper |
|
hh/ |
HTML Help viewer |
|
icinfo/ |
List/Configure installed Video Compressors |
|
iexplore/ |
Internet Explorer replacement |
|
msiexec/ |
Microsoft Installer frontend |
|
net/ |
Network and User-Management |
|
notepad/ |
Notepad replacement |
|
oleview/ |
OLE/COM Object Viewer |
|
progman/ |
Program manager |
|
regedit/ |
Registry editor |
|
regsvr32/ |
Register COM server |
|
rpcss/ |
RPC services |
|
rundll32/ |
Execute DLL functions directly |
|
spoolsv/ |
Spooler service |
|
start/ |
Replacement for start.exe |
|
svchost/ |
Replacement for svchost.exe (Hosting services) |
|
taskmgr/ |
Manage running Windows/ Winelib applications |
|
uninstaller/ |
Remove installed programs |
|
view/ |
Metafile viewer |
|
wineboot/ |
Wine bootstrap process |
|
winebrowser/ |
Frontend for Webbrowsers on the Host |
|
winecfg/ |
Wine configuration utility |
|
wineconsole/ |
Console |
|
winedbg/ |
Debugger |
|
winedevice/ |
Wine service to load win32 kernel drivers |
|
winefile/ |
File manager |
|
winemenubuilder/ |
Helper program for building Unix menu entries |
|
winemine/ |
Mine game |
|
winepath/ |
Translate between Wine and Unix paths |
|
winetest/ |
Wine testing shell |
|
winevdm/ |
Wine virtual DOS machine |
|
winhelp/ |
Help viewer |
|
winver/ |
Windows Version Program |
|
wordpad/ |
Wordpad replacement |
|
write/ |
Write replacement that calls wordpad.exe |
|
xcopy/ |
Filecopy tool |
|
Support programs, libraries, etc:
|
||
dlls/dxerr8/ |
DirectX 8 error import lib |
|
dlls/dxerr9/ |
DirectX 9 error import lib |
|
dlls/dxguid/ |
DirectX UUID import lib |
|
dlls/strmiids/ |
Exports class CLSIDs and interface IIDs |
|
dlls/uuid/ |
Windows-compatible UUID import lib |
|
documentation/ |
some documentation |
|
include/ |
Windows standard includes |
|
include/ddk/ |
Windows DDK compatible headers |
|
include/msvcrt/ |
MSVC compatible libc headers |
|
include/wine/ |
Wine specific headers |
|
libs/ |
the Wine libraries |
|
libs/port/ |
portability library |
|
libs/wine/ |
Wine bootstrap and unicode support library |
|
libs/wpp/ |
C preprocessor |
|
loader/ |
the main Wine loader |
|
server/ |
the Wine server |
|
tools/ |
various tools used to build/check Wine |
|
tools/widl/ |
the IDL compiler |
|
tools/winapi/ |
A Win32 API checker |
|
tools/winebuild/ |
Wine build tool |
|
tools/winedump/ |
a .DLL dump utility |
|
tools/winegcc/ |
a MinGW command line compatible gcc wrapper |
|
tools/winemaker/ |
a Makefile generator for winelib |
|
tools/wmc/ |
the message compiler |
|
tools/wrc/ |
the resource compiler |
|
Implementing new API calls
This is the simple version, and covers only Win32. Win16 is slightly uglier, because of the Pascal heritage and the segmented memory model. All of the Win32 APIs known to Wine are listed in the .spec file of their corresponding dll. An unimplemented call will look like (from gdi32.spec)
@ stub PolyPatBlt
To implement this call, you need to do the following four things:
1. Find the appropriate parameters for the call, and add a prototype to the correct header file. In this case, that means include/wingdi.h, and it might look like
BOOL WINAPI PolyPatBlt(HDC, LPCVOID, DWORD);
If the function has both an ASCII and a Unicode version, you need to define both and add a #define WINELIB_NAME_AW declaration. See below for discussion of function naming conventions.
2. Modify the .spec file to tell Wine that the function has an implementation, what the parameters look like and what Wine function to use for the implementation. In Win32, things are simple--everything is 32-bits. However, the relay code handles pointers and pointers to strings slightly differently, so you should use 'str' and 'wstr' for strings, 'ptr' for other pointer types, and 'long' for everything else:
@ stdcall PolyPatBlt(long ptr long)
The PolyPatBlt at the end of the line is which Wine function to use for the implementation.
3. Implement the function as a stub. Once you add the function to the .spec file, you must add the function to the Wine source before it will link. Add a function called PolyPatBlt somewhere. Good things to put into a stub:
- a correct prototype, including the WINAPI
header comments, including full documentation for the function and arguments (see documentation/README.documentation)
- A FIXME message and an appropriate return value are good things to put in a stub. NOTE: When submitting documentation changes, you must clearly state that when creating your patch that you did not copy the function documentation from MSDN. When implementing a new function it is fine to look at the API documentation on MSDN however the api documentation must be written in your own words.
/************************************************************
* PolyPatBlt (GDI32.@)
*
* Draw many Bezier curves.
*
* PARAMS
* hdc [I] Device context to draw to
* p [I] Array of POINT structs
* count [I] Number of points in p
*
* RETURNS
* Success: Non-zero.
* Failure: FALSE. Use GetLastError() to find the error cause.
*
* BUGS
* Unimplemented
*/
BOOL WINAPI PolyPatBlt(HDC hdc, LPCVOID p, DWORD count)
{
/* tell the user they've got a substandard implementation */
FIXME("(%x,%p,%d): stub\n", hdc, p, count);
/* some programs may be able to compensate,
* if they know what happened
*/
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
return FALSE; /* error value */
}
4. Implement and test the rest of the function:
- Add a test to the Wine test suite, when possible.
- Learn from the test results, what Windows does (MSDN is sometimes incomplete or wrong).
- It's a good idea to ask for test results for other Windows versions in wine-devel.
- Try to limit the supported formats/versions in a function for a single patch.
- Add support for additional formats/versions in the next patches, when needed.
Implementing a new DLL
Generic directions
Apart from writing the set of needed .c files, you also need to do the following:
Create a directory <MyDll> where to store the implementation of the DLL. This directory has to be put under the dlls/ directory. If the DLL exists under Windows as both 16 and 32 bit DLL, use a single directory with the Name of the 32 bit DLL for both implementations.
Create the Makefile.in in the ./dlls/<MyDll>/ directory. You can copy an existing Makefile.in from another ./dlls/ subdirectory. You need at least to change the MODULE and C_SRCS macros.
Create the .spec file for the DLL exported functions in your directory. Refer to Implementation of new API calls earlier in this document for more information on this part.
Important note, when using git: you must do git add dlls/<MyDll>/Makefile.in before you call ./tools/make_makefiles, or make_makefiles won't know about your dll
Call ./tools/make_makefiles from the top of the Wine tree. Your new dll is now integrated in the Wine build environment. Verify this by making sure the name of your dll directory appears in configure.ac.
If you added new test(s) in configure.ac, run autoheader to add the needed variables to include/config.in.h
Regenerate the ./configure script with autoconf.
Run ./configure from the top of the Wine tree. You should now have a Makefile file in ./dlls/<MyDll>/
- To include a Windows-DLL in the official Wine Tree, please submit the smallest possible implementation first:
- Only "DLLMain" in a single .c file
- the .spec file with the exported functions declared as stub
your Makefile.in
do not include any autogenerated source
When your new DLL is in the Wine Tree, please add the DLL and a short Description at the top of this Page
You can now start adding .c files. For the .h files, if they are standard Windows one, put them in include/. If they are linked to your implementation of the dll, put them in your newly created directory
- Pick only one Function or a small set of Functions for a Patch:
- reduced Patch-Size
- reduced complexity
- increased motivation to review
Add a set of tests as explained below
You should not include any autogenerated source, that was created from 'autoconf' or a tool inside 'tools/' (make_makefiles or winedump as examples), when you submit your Patch to winehq.org
Debug channels
If you need to create a new debug channel, just add
#include "wine/debug.h"
and macro
WINE_DEFAULT_DEBUG_CHANNEL(mydll)
to your .c file(s), and use them. (The prefered Name for the debug-channel is your DLL-Name) All the housekeeping will happen automatically.
See the Examples in Debug Messages later in this Document.
Makefiles
The Makefile.in is a bit different to the generated Makefile. Have a good look at an example and use the right values otherwise it won't necessarily be recognised. If your .dlls/<MyDll>/<MyDll>.spec exports any functions then you need a
IMPORTLIB = <MyDll>
statement. Otherwise leave it out as you will get warnings that the dll does not export anything.
Resources
If you also need to add resources to your DLL, then create the .rc file. Add to your ./dlls/<MyDll>/Makefile.in, in the RC_SRCS macro, the list of .rc files to add to the DLL. See dlls/comctl32/ for an example of this.
Adding a tests directory
If you want to add tests to an existing dll and there is already a tests directory things should be clear enough. However if the dll does not yet have a tests subdirectory you will need to add one and set it up.
In the dll's subdirectory create a subdirectory named tests.
In that tests subdirectory copy a Makefile.in from some other tests subdirectory and edit it.
- Change the TESTDLL to the dll you are testing
- Change the IMPORTS to the dll you are testing and also anything it requires
- EXTRALIBS is sometimes needed (DLL use COM as Example)
- Change the CTESTS entry to the list of c source files you will provide containing the tests.
- I do not yet know what the generated.c file is all about.
- Write the c source files that you added to the CTESTS entry above.
Important note, when using git: Makefile.in must be added to the index before you call ./tools/make_makefiles
Call ./tools/make_makefiles from the top of the Wine tree. Your new tests are now integrated in the Wine build environment
Regenerate the ./configure script with autoconf.
Run ./configure from the top of the Wine tree. You should now have a Makefile file in ./dlls/<MyDll>/tests/.
You chould now be able to run 'make depend' and make.
- With a recent Cross-Compiler (MinGW) , you can build your tests as Windows-Binary.
- Make sure, your tests works without failure on different Systems. (Windows and wine, and there is a 'todo_wine' - macro).
- Ask other People for Help to run your tests.
You should not include any autogenerated code, that was created from 'autoconf' or a tool inside 'tools/' (tools/make_makefiles as example), when you submit your Patch to winehq.org
Writing Conformance Tests
Wine uses test-driven development to a large extent; we write a test, make sure it passes on Windows, and then get it to pass on Wine by fixing Wine.
See http://www.winehq.org/site/docs/winedev-guide/testing
See also WritingConformanceTests for more notes.
Memory and segments
NE (Win16) executables consist of multiple segments. The Wine loader loads each segment into a unique location in the Wine processes memory and assigns a selector to that segment. Because of this, it's not possible to exchange addresses freely between 16-bit and 32-bit code. Addresses used by 16-bit code are segmented addresses (16:16), formed by a 16-bit selector and a 16-bit offset. Those used by the Wine code are regular 32-bit linear addresses.
There are three ways to obtain a segmented pointer:
- Using the MapLS function (recommended).
Allocate a block of memory from the global heap and use WIN16_GlobalLock to get its segmented address.
- Declare the argument as 'segptr' instead of 'ptr' in the spec file for a given API function.
Once you have a segmented pointer, it must be converted to a linear pointer before you can use it from 32-bit code. This can be done with the MapSL function. The linear pointer can then be used freely with standard Unix functions like memcpy() etc. without worrying about 64k boundaries. Note: there's no easy way to convert back from a linear to a segmented address.
In most cases, you don't need to worry about segmented address, as the conversion is made automatically by the callback code and the API functions only see linear addresses. However, in some cases it is necessary to manipulate segmented addresses; the most frequent cases are:
- API functions that return a pointer
- lParam of Windows messages that point to a structure
- Pointers contained inside structures accessed by 16-bit code.
It is usually a good practice to used the type SEGPTR for segmented pointers, instead of something like LPSTR or char *. As SEGPTR is defined as a DWORD, you'll get a compilation warning if you mistakenly use it as a regular 32-bit pointer.
Structure packing
By default both Microsoft and gcc compilers align structure members (e.g. WORDs are on a WORD boundary, etc.). This means that a structure like
struct { BYTE x; WORD y; };
will take 4 bytes, because a compiler will add a dummy byte between x and y. Sometimes to have the correct layout for structures used by Windows code, you need to embed the struct within two special #include's which will take care of the packing for you:
#include "pshpack1.h"
struct { BYTE x; WORD y; };
#include "poppack1.h"
For alignment on a 2-byte boundary, there is a pshpack2.h, etc.
Naming conventions for API functions and types
In order to support both Win16 and Win32 APIs within the same source code, the following convention must be used in naming all API functions and types. If the Windows API uses the name 'xxx', the Wine code must use:
- 'xxx16' for the Win16 version, - 'xxx' for the Win32 version when no strings are involved, - 'xxxA' for the Win32 version with ASCII strings, - 'xxxW' for the Win32 version with Unicode strings.
If the function has both ASCII and Unicode version, you should then use the macros WINELIB_NAME_AW(xxx) or DECL_WINELIB_TYPE_AW(xxx) (defined in include/windef.h) to define the correct 'xxx' function or type for Winelib. When compiling Wine itself, 'xxx' is not defined, meaning that code inside of Wine must always specify explicitly the ASCII or Unicode version.
If 'xxx' is the same in Win16 and Win32, you can simply use the same name as Windows, i.e. just 'xxx'. If 'xxx' is Win16 only, you could use the name as is, but it's preferable to use 'xxx16' to make it clear it is a Win16 function.
For example:
typedef struct { /* Win32 ASCII data structure */ } WNDCLASSA;
typedef struct { /* Win32 Unicode data structure */ } WNDCLASSW;
typedef struct { /* Win16 data structure */ } WNDCLASS16;
DECL_WINELIB_TYPE_AW(WNDCLASS);
ATOM RegisterClass16( WNDCLASS16 * );
ATOM RegisterClassA( WNDCLASSA * );
ATOM RegisterClassW( WNDCLASSW * );
#define RegisterClass WINELIB_NAME_AW(RegisterClass)
The Winelib user can then say:
WNDCLASS wc = { ... };
RegisterClass( &wc );
and this will use the correct declaration depending on the definition of the UNICODE symbol.
Debug messages
To display a message only during debugging, you normally write something like this:
TRACE("abc..."); or
FIXME("abc..."); or
WARN("abc..."); or
ERR("abc...");
depending on the seriousness of the problem. You need to declare the debug channel name at the top of the file (after the includes) using the WINE_DEFAULT_DEBUG_CHANNEL macro, like so:
WINE_DEFAULT_DEBUG_CHANNEL(win);
If your debugging code is more complex than just printf, you can use the macros:
TRACE_ON(xxx), WARN_ON(xxx), ERR_ON(xxx) and FIXME_ON(xxx)
to test if the given channel is enabled. Thus, you can write:
if (TRACE_ON(win)) DumpSomeStructure(&str);
Don't worry about the inefficiency of the test. If it is permanently disabled (that is TRACE_ON(win) is 0 at compile time), the compiler will eliminate the dead code.
For more info about debugging messages, http://www.winehq.org/site/docs/winedev-guide/debugging
Translating resource files
The binary files can contain the same resource in several languages. The language of the resource to load is chosen basing on the user settings. For example "LANG=ja_JP winecfg" will launch winecfg in japanese.
General recommendations and tips:
- There is one resource file per language, that is per LANG_XXX constant. The name of that resource file ends in 'Xx.rc' where Xx is the two-character code for that language.
Be careful not to translate too much. In the following example 'C&ollate' must be translated but not 'Button' or any of the other words.
CONTROL "C&ollate", chx2,"Button",BS_AUTOCHECKBOX | WS_GROUP | WS_TABSTOP,240,130,36,12
- It is ok to only translate the strings. However, to get a clean look, it may then be necessary to adjust the dialog layout, especially when the translated string is longer. The dialog layout is defined by the sequence of numbers, for instance '240,130,36,12' in the example above. Unfortunately this requires compiling Wine and finding an application to test the dialog.
By default the resource files uses the Windows codepage for the given language. A list of codepages for locales can be found at http://msdn.microsoft.com/en-us/library/dd317756(VS.85).aspx. Some editors allows you to chose the codepage of the edited page, you can use the iconv command line utility to convert a file to UTF-8 (the charset used by all modern Linux and Mac OS X) and then back to the Windows codepage or you can use the Wine Notepad to edit it. However if you choose Notepad then it may add Windows line ending to the file that you will need to remove. You can also declare a file as UTF-8 by adding "#pragma code_page(65001)" at the top of the file. You won't be able to compile such a file using the Microsoft Resource Compiler but that's not a problem.
There are also a number of aspects to be aware of when working on a translation for a language that has multiple sublanguages:
- The 'Xx.rc' file contains the translations for all of that language's sublanguages. So before updating a translation, first make sure that it corresponds to your sublanguage.
- It is recommended to avoid using 'SUBLANG_DEFAULT' because it is ambiguous. For instance, does 'LANG_PORTUGUESE, SUBLANG_DEFAULT' refer to Portuguese or Brazilian Portuguese? This question is impossible to answer without consulting 'winnt.h'. Contrast this with 'LANG_PORTUGUESE, SUBLANG_PORTUGUESE_BRAZILIAN' which is unambiguous.
- If a translation is the same for all sublanguages, then use 'SUBLANG_NEUTRAL' as the sublanguage.
A list of languages that should use LANG_NEUTRAL can be found on SublangNeutral.
- It is recommended to group all the translations for a given dialog or resource together. For instance:
LANGUAGE LANG_PORTUGUESE, SUBLANG_PORTUGUESE_BRAZILIAN
STRINGTABLE DISCARDABLE
{
IDS_SAVE_BUTTON "&Salvar"
}
LANGUAGE LANG_PORTUGUESE, SUBLANG_PORTUGUESE
STRINGTABLE DISCARDABLE
{
IDS_SAVE_BUTTON "&Gravar"
}
LANGUAGE LANG_PORTUGUESE, SUBLANG_PORTUGUESE_BRAZILIAN
NEWFILEOPENORD DIALOG LOADONCALL MOVEABLE DISCARDABLE 0, 0, 280, 164
...
- The goal is to make it easier to compare the translations, and, for instance, maybe merge them and mark them as SUBLANG_NEUTRAL.
See Also: Translating
Coding Conventions
Here are a couple of things to bear in mind in any patches you make.
More info
Win32 API documentation on MSDN: http://msdn.microsoft.com/
Analyse by Geoff Chappell: http://www.geoffchappell.com/
Undocumented Windows 2000 Secrets : http://www.rawol.com/?topic=41
- In 1993 Dr. Dobbs Journal published a column called "Undocumented Corner".
http://msdn2.microsoft.com/en-us/library/cc230273.aspx - Windows Data Types
