Authors: Gavriel State <gavriels@corel.com>, Ulrich Czekalla <ulrichc@corel.com>
[wine] / include / windef.h
1 /*
2  * Basic types definitions
3  *
4  * Copyright 1996 Alexandre Julliard
5  */
6
7 #ifndef __WINE_WINDEF_H
8 #define __WINE_WINDEF_H
9
10 #ifdef __WINE__
11 # include "config.h"
12 # undef UNICODE
13 #endif  /* __WINE__ */
14
15 #ifdef __cplusplus
16 extern "C" {
17 #endif
18
19 /* Misc. constants. */
20
21 #ifdef FALSE
22 #undef FALSE
23 #endif
24 #define FALSE 0
25
26 #ifdef TRUE
27 #undef TRUE
28 #endif
29 #define TRUE  1
30
31 #ifdef NULL
32 #undef NULL
33 #endif
34 #define NULL  0
35
36 /* Macros to map Winelib names to the correct implementation name */
37 /* depending on __WINE__ and UNICODE macros.                      */
38 /* Note that Winelib is purely Win32.                             */
39
40 #ifdef __WINE__
41 # define WINELIB_NAME_AW(func) \
42     func##_must_be_suffixed_with_W_or_A_in_this_context \
43     func##_must_be_suffixed_with_W_or_A_in_this_context
44 #else  /* __WINE__ */
45 # ifdef UNICODE
46 #  define WINELIB_NAME_AW(func) func##W
47 # else
48 #  define WINELIB_NAME_AW(func) func##A
49 # endif  /* UNICODE */
50 #endif  /* __WINE__ */
51
52 #ifdef __WINE__
53 # define DECL_WINELIB_TYPE_AW(type)  /* nothing */
54 #else   /* __WINE__ */
55 # define DECL_WINELIB_TYPE_AW(type)  typedef WINELIB_NAME_AW(type) type;
56 #endif  /* __WINE__ */
57
58 #ifndef NONAMELESSSTRUCT
59 # if defined(__WINE__) || !defined(_FORCENAMELESSSTRUCT)
60 #  define NONAMELESSSTRUCT
61 # endif
62 #endif /* !defined(NONAMELESSSTRUCT) */
63
64 #ifndef NONAMELESSUNION
65 # if defined(__WINE__) || !defined(_FORCENAMELESSUNION) || !defined(__cplusplus)
66 #  define NONAMELESSUNION
67 # endif
68 #endif /* !defined(NONAMELESSUNION) */
69
70 #ifndef NONAMELESSSTRUCT
71 #define DUMMYSTRUCTNAME
72 #define DUMMYSTRUCTNAME1
73 #define DUMMYSTRUCTNAME2
74 #define DUMMYSTRUCTNAME3
75 #define DUMMYSTRUCTNAME4
76 #define DUMMYSTRUCTNAME5
77 #else /* !defined(NONAMELESSSTRUCT) */
78 #define DUMMYSTRUCTNAME   s
79 #define DUMMYSTRUCTNAME1  s1
80 #define DUMMYSTRUCTNAME2  s2
81 #define DUMMYSTRUCTNAME3  s3
82 #define DUMMYSTRUCTNAME4  s4
83 #define DUMMYSTRUCTNAME5  s5
84 #endif /* !defined(NONAMELESSSTRUCT) */
85
86 #ifndef NONAMELESSUNION
87 #define DUMMYUNIONNAME
88 #define DUMMYUNIONNAME1
89 #define DUMMYUNIONNAME2
90 #define DUMMYUNIONNAME3
91 #define DUMMYUNIONNAME4
92 #define DUMMYUNIONNAME5
93 #else /* !defined(NONAMELESSUNION) */
94 #define DUMMYUNIONNAME   u
95 #define DUMMYUNIONNAME1  u1
96 #define DUMMYUNIONNAME2  u2
97 #define DUMMYUNIONNAME3  u3
98 #define DUMMYUNIONNAME4  u4
99 #define DUMMYUNIONNAME5  u5
100 #endif /* !defined(NONAMELESSUNION) */
101
102 /* Calling conventions definitions */
103
104 #ifdef __i386__
105 # if defined(__GNUC__) && ((__GNUC__ > 2) || ((__GNUC__ == 2) && (__GNUC_MINOR__ >= 7)))
106 #  define __stdcall __attribute__((__stdcall__))
107 #  define __cdecl   __attribute__((__cdecl__))
108 #  define __RESTORE_ES  __asm__ __volatile__("pushl %ds\n\tpopl %es")
109 # else
110 #  error You need gcc >= 2.7 to build Wine on a 386
111 # endif  /* __GNUC__ */
112 #else  /* __i386__ */
113 # define __stdcall
114 # define __cdecl
115 # define __RESTORE_ES
116 #endif  /* __i386__ */
117
118 #define CALLBACK    __stdcall
119 #define WINAPI      __stdcall
120 #define APIPRIVATE  __stdcall
121 #define PASCAL      __stdcall
122 #define pascal      __stdcall
123 #define _pascal     __stdcall
124 #define _stdcall    __stdcall
125 #define _fastcall   __stdcall
126 #define __fastcall  __stdcall
127 #define __export    __stdcall
128 #define CDECL       __cdecl
129 #define _CDECL      __cdecl
130 #define cdecl       __cdecl
131 #define _cdecl      __cdecl
132 #define WINAPIV     __cdecl
133 #define APIENTRY    WINAPI
134
135 #define __declspec(x)
136 #define dllimport
137 #define dllexport
138
139 #define CONST       const
140
141 /* Standard data types. These are the same for emulator and library. */
142
143 typedef void            VOID;
144 typedef int             INT;
145 typedef unsigned int    UINT;
146 typedef unsigned short  WORD;
147 typedef unsigned long   DWORD;
148 typedef unsigned long   ULONG;
149 typedef unsigned char   BYTE;
150 typedef long            LONG;
151 typedef short           SHORT;
152 typedef unsigned short  USHORT;
153 typedef char            CHAR;
154 typedef unsigned char   UCHAR;
155 /* Some systems might have wchar_t, but we really need 16 bit characters */
156 typedef unsigned short  WCHAR;
157 typedef int             BOOL;
158 typedef double          DATE;
159 typedef double          DOUBLE;
160 typedef double          LONGLONG;
161 typedef double          ULONGLONG;
162
163 /* FIXME: Wine does not compile with strict on, therefore strict
164  * handles are presently only usable on machines where sizeof(UINT) ==
165  * sizeof(void*).  HANDLEs are supposed to be void* but a large amount
166  * of WINE code operates on HANDLES as if they are UINTs. So to WINE
167  * they exist as UINTs but to the Winelib user who turns on strict,
168  * they exist as void*. If there is a size difference between UINT and
169  * void* then things get ugly.  */
170 #ifdef STRICT
171 typedef VOID*           HANDLE;
172 #else
173 typedef UINT            HANDLE;
174 #endif
175
176
177 typedef HANDLE         *LPHANDLE;
178
179 /* Integer types. These are the same for emulator and library. */
180 typedef UINT            WPARAM;
181 typedef LONG            LPARAM;
182 typedef LONG            HRESULT;
183 typedef LONG            LRESULT;
184 typedef WORD            ATOM;
185 typedef WORD            CATCHBUF[9];
186 typedef WORD           *LPCATCHBUF;
187 typedef HANDLE          HHOOK;
188 typedef HANDLE          HMONITOR;
189 typedef DWORD           LCID;
190 typedef WORD            LANGID;
191 typedef DWORD           LCTYPE;
192 typedef float           FLOAT;
193
194 /* Pointers types. These are the same for emulator and library. */
195 /* winnt types */
196 typedef VOID           *PVOID;
197 typedef const void     *PCVOID;
198 typedef CHAR           *PCHAR;
199 typedef UCHAR          *PUCHAR;
200 typedef BYTE           *PBYTE;
201 typedef WORD           *PWORD;
202 typedef USHORT         *PUSHORT;
203 typedef SHORT          *PSHORT;
204 typedef ULONG          *PULONG;
205 typedef LONG           *PLONG;
206 typedef DWORD          *PDWORD;
207 /* common win32 types */
208 typedef CHAR           *LPSTR;
209 typedef CHAR           *PSTR;
210 typedef const CHAR     *LPCSTR;
211 typedef const CHAR     *PCSTR;
212 typedef WCHAR          *LPWSTR;
213 typedef WCHAR          *PWSTR;
214 typedef const WCHAR    *LPCWSTR;
215 typedef const WCHAR    *PCWSTR;
216 typedef BYTE           *LPBYTE;
217 typedef WORD           *LPWORD;
218 typedef DWORD          *LPDWORD;
219 typedef LONG           *LPLONG;
220 typedef VOID           *LPVOID;
221 typedef const VOID     *LPCVOID;
222 typedef INT            *PINT;
223 typedef INT            *LPINT;
224 typedef UINT           *PUINT;
225 typedef UINT           *LPUINT;
226 typedef FLOAT          *PFLOAT;
227 typedef FLOAT          *LPFLOAT;
228 typedef BOOL           *PBOOL;
229 typedef BOOL           *LPBOOL;
230
231 /* Special case: a segmented pointer is just a pointer in the user's code. */
232
233 #ifdef __WINE__
234 typedef DWORD SEGPTR;
235 #else
236 typedef void* SEGPTR;
237 #endif /* __WINE__ */
238
239 /* Handle types that exist both in Win16 and Win32. */
240
241 #ifdef STRICT
242 #define DECLARE_HANDLE(a) \
243         typedef struct a##__ { int unused; } *a; \
244         typedef a *P##a; \
245         typedef a *LP##a
246 #else /*STRICT*/
247 #define DECLARE_HANDLE(a) \
248         typedef HANDLE a; \
249         typedef a *P##a; \
250         typedef a *LP##a
251 #endif /*STRICT*/
252
253 DECLARE_HANDLE(HACMDRIVERID);
254 DECLARE_HANDLE(HACMDRIVER);
255 DECLARE_HANDLE(HACMOBJ);
256 DECLARE_HANDLE(HACMSTREAM);
257 DECLARE_HANDLE(HMETAFILEPICT);
258
259 DECLARE_HANDLE(HACCEL);
260 DECLARE_HANDLE(HBITMAP);
261 DECLARE_HANDLE(HBRUSH);
262 DECLARE_HANDLE(HCOLORSPACE);
263 DECLARE_HANDLE(HCURSOR);
264 DECLARE_HANDLE(HDC);
265 DECLARE_HANDLE(HDROP);
266 DECLARE_HANDLE(HDRVR);
267 DECLARE_HANDLE(HDWP);
268 DECLARE_HANDLE(HENHMETAFILE);
269 DECLARE_HANDLE(HFILE);
270 DECLARE_HANDLE(HFONT);
271 DECLARE_HANDLE(HICON);
272 DECLARE_HANDLE(HINSTANCE);
273 DECLARE_HANDLE(HKEY);
274 DECLARE_HANDLE(HMENU);
275 DECLARE_HANDLE(HMETAFILE);
276 DECLARE_HANDLE(HMIDI);
277 DECLARE_HANDLE(HMIDIIN);
278 DECLARE_HANDLE(HMIDIOUT);
279 DECLARE_HANDLE(HMIDISTRM);
280 DECLARE_HANDLE(HMIXER);
281 DECLARE_HANDLE(HMIXEROBJ);
282 DECLARE_HANDLE(HMMIO);
283 DECLARE_HANDLE(HPALETTE);
284 DECLARE_HANDLE(HPEN);
285 DECLARE_HANDLE(HQUEUE);
286 DECLARE_HANDLE(HRGN);
287 DECLARE_HANDLE(HRSRC);
288 DECLARE_HANDLE(HTASK);
289 DECLARE_HANDLE(HWAVE);
290 DECLARE_HANDLE(HWAVEIN);
291 DECLARE_HANDLE(HWAVEOUT);
292 DECLARE_HANDLE(HWINSTA);
293 DECLARE_HANDLE(HDESK);
294 DECLARE_HANDLE(HWND);
295 DECLARE_HANDLE(HKL);
296 DECLARE_HANDLE(HIC);
297 DECLARE_HANDLE(HRASCONN);
298
299 /* Handle types that must remain interchangeable even with strict on */
300
301 typedef HINSTANCE HMODULE;
302 typedef HANDLE HGDIOBJ;
303 typedef HANDLE HGLOBAL;
304 typedef HANDLE HLOCAL;
305 typedef HANDLE GLOBALHANDLE;
306 typedef HANDLE LOCALHANDLE;
307
308 /* Callback function pointers types */
309
310 typedef BOOL    (CALLBACK* DATEFMT_ENUMPROCA)(LPSTR);
311 typedef BOOL    (CALLBACK* DATEFMT_ENUMPROCW)(LPWSTR);
312 DECL_WINELIB_TYPE_AW(DATEFMT_ENUMPROC)
313 typedef BOOL    (CALLBACK *DLGPROC)(HWND,UINT,WPARAM,LPARAM);
314 typedef LRESULT (CALLBACK *DRIVERPROC)(DWORD,HDRVR,UINT,LPARAM,LPARAM);
315 typedef INT     (CALLBACK *EDITWORDBREAKPROCA)(LPSTR,INT,INT,INT);
316 typedef INT     (CALLBACK *EDITWORDBREAKPROCW)(LPWSTR,INT,INT,INT);
317 DECL_WINELIB_TYPE_AW(EDITWORDBREAKPROC)
318 typedef LRESULT (CALLBACK *FARPROC)();
319 typedef INT     (CALLBACK *PROC)();
320 typedef BOOL    (CALLBACK *GRAYSTRINGPROC)(HDC,LPARAM,INT);
321 typedef LRESULT (CALLBACK *HOOKPROC)(INT,WPARAM,LPARAM);
322 typedef BOOL    (CALLBACK *PROPENUMPROCA)(HWND,LPCSTR,HANDLE);
323 typedef BOOL    (CALLBACK *PROPENUMPROCW)(HWND,LPCWSTR,HANDLE);
324 DECL_WINELIB_TYPE_AW(PROPENUMPROC)
325 typedef BOOL    (CALLBACK *PROPENUMPROCEXA)(HWND,LPCSTR,HANDLE,LPARAM);
326 typedef BOOL    (CALLBACK *PROPENUMPROCEXW)(HWND,LPCWSTR,HANDLE,LPARAM);
327 DECL_WINELIB_TYPE_AW(PROPENUMPROCEX)
328 typedef BOOL    (CALLBACK* TIMEFMT_ENUMPROCA)(LPSTR);
329 typedef BOOL    (CALLBACK* TIMEFMT_ENUMPROCW)(LPWSTR);
330 DECL_WINELIB_TYPE_AW(TIMEFMT_ENUMPROC)
331 typedef VOID    (CALLBACK *TIMERPROC)(HWND,UINT,UINT,DWORD);
332 typedef BOOL (CALLBACK *WNDENUMPROC)(HWND,LPARAM);
333 typedef LRESULT (CALLBACK *WNDPROC)(HWND,UINT,WPARAM,LPARAM);
334
335 /*----------------------------------------------------------------------------
336 ** FIXME:  Better isolate Wine's reliance on the xxx16 type definitions.
337 **         For now, we just isolate them to make the situation clear.
338 **--------------------------------------------------------------------------*/
339 #include "wine/windef16.h"
340
341 /* Define some empty macros for compatibility with Windows code. */
342
343 #ifndef __WINE__
344 #define NEAR
345 #define FAR
346 #define near
347 #define far
348 #define _near
349 #define _far
350 #define IN
351 #define OUT
352 #define OPTIONAL
353 #endif  /* __WINE__ */
354
355 /* Macro for structure packing. */
356
357 #ifdef __GNUC__
358 #define WINE_PACKED   __attribute__((packed))
359 #define WINE_UNUSED   __attribute__((unused))
360 #define WINE_NORETURN __attribute__((noreturn))
361 #else
362 #define WINE_PACKED    /* nothing */
363 #define WINE_UNUSED    /* nothing */
364 #define WINE_NORETURN  /* nothing */
365 #endif
366
367 /* Macros to split words and longs. */
368
369 #define LOBYTE(w)              ((BYTE)(WORD)(w))
370 #define HIBYTE(w)              ((BYTE)((WORD)(w) >> 8))
371
372 #define LOWORD(l)              ((WORD)(DWORD)(l))
373 #define HIWORD(l)              ((WORD)((DWORD)(l) >> 16))
374
375 #define SLOWORD(l)             ((INT16)(LONG)(l))
376 #define SHIWORD(l)             ((INT16)((LONG)(l) >> 16))
377
378 #define MAKEWORD(low,high)     ((WORD)(((BYTE)(low)) | ((WORD)((BYTE)(high))) << 8))
379 #define MAKELONG(low,high)     ((LONG)(((WORD)(low)) | (((DWORD)((WORD)(high))) << 16)))
380 #define MAKELPARAM(low,high)   ((LPARAM)MAKELONG(low,high))
381 #define MAKEWPARAM(low,high)   ((WPARAM)MAKELONG(low,high))
382 #define MAKELRESULT(low,high)  ((LRESULT)MAKELONG(low,high))
383 #define MAKEINTATOM(atom)      ((LPCSTR)MAKELONG((atom),0))
384
385 #define SELECTOROF(ptr)     (HIWORD(ptr))
386 #define OFFSETOF(ptr)       (LOWORD(ptr))
387
388 #ifdef __WINE__
389 /* macros to set parts of a DWORD (not in the Windows API) */
390 #define SET_LOWORD(dw,val)  ((dw) = ((dw) & 0xffff0000) | LOWORD(val))
391 #define SET_LOBYTE(dw,val)  ((dw) = ((dw) & 0xffffff00) | LOBYTE(val))
392 #define SET_HIBYTE(dw,val)  ((dw) = ((dw) & 0xffff00ff) | (LOWORD(val) & 0xff00))
393 #define ADD_LOWORD(dw,val)  ((dw) = ((dw) & 0xffff0000) | LOWORD((DWORD)(dw)+(val)))
394 #endif
395
396 /* Macros to access unaligned or wrong-endian WORDs and DWORDs. */
397 /* Note: These macros are semantically broken, at least for wrc.  wrc
398    spits out data in the platform's current binary format, *not* in 
399    little-endian format.  These macros are used throughout the resource
400    code to load and store data to the resources.  Since it is unlikely 
401    that we'll ever be dealing with little-endian resource data, the 
402    byte-swapping nature of these macros has been disabled.  Rather than 
403    remove the use of these macros from the resource loading code, the
404    macros have simply been disabled.  In the future, someone may want 
405    to reactivate these macros for other purposes.  In that case, the
406    resource code will have to be modified to use different macros. */ 
407
408 #if 1
409 #define PUT_WORD(ptr,w)   (*(WORD *)(ptr) = (w))
410 #define GET_WORD(ptr)     (*(WORD *)(ptr))
411 #define PUT_DWORD(ptr,dw) (*(DWORD *)(ptr) = (dw))
412 #define GET_DWORD(ptr)    (*(DWORD *)(ptr))
413 #else
414 #define PUT_WORD(ptr,w)   (*(BYTE *)(ptr) = LOBYTE(w), \
415                            *((BYTE *)(ptr) + 1) = HIBYTE(w))
416 #define GET_WORD(ptr)     ((WORD)(*(BYTE *)(ptr) | \
417                                   (WORD)(*((BYTE *)(ptr)+1) << 8)))
418 #define PUT_DWORD(ptr,dw) (PUT_WORD((ptr),LOWORD(dw)), \
419                            PUT_WORD((WORD *)(ptr)+1,HIWORD(dw)))
420 #define GET_DWORD(ptr)    ((DWORD)(GET_WORD(ptr) | \
421                                    ((DWORD)GET_WORD((WORD *)(ptr)+1) << 16)))
422 #endif  /* 1 */
423
424 /* min and max macros */
425 #define __max(a,b) (((a) > (b)) ? (a) : (b))
426 #define __min(a,b) (((a) < (b)) ? (a) : (b))
427 #ifndef max
428 #define max(a,b)   (((a) > (b)) ? (a) : (b))
429 #endif
430 #ifndef min
431 #define min(a,b)   (((a) < (b)) ? (a) : (b))
432 #endif
433
434 #define _MAX_PATH  260
435 #define MAX_PATH   260
436 #define _MAX_DRIVE 3
437 #define _MAX_DIR   256
438 #define _MAX_FNAME 255
439 #define _MAX_EXT   256
440
441 #define HFILE_ERROR16   ((HFILE16)-1)
442 #define HFILE_ERROR     ((HFILE)-1)
443
444 /* The SIZE structure */
445 typedef struct tagSIZE
446 {
447     INT  cx;
448     INT  cy;
449 } SIZE, *PSIZE, *LPSIZE;
450
451
452 typedef SIZE SIZEL, *PSIZEL, *LPSIZEL;
453
454 #define CONV_SIZE16TO32(s16,s32) \
455             ((s32)->cx = (INT)(s16)->cx, (s32)->cy = (INT)(s16)->cy)
456 #define CONV_SIZE32TO16(s32,s16) \
457             ((s16)->cx = (INT16)(s32)->cx, (s16)->cy = (INT16)(s32)->cy)
458
459 /* The POINT structure */
460 typedef struct tagPOINT
461 {
462     LONG  x;
463     LONG  y;
464 } POINT, *PPOINT, *LPPOINT;
465
466 typedef struct _POINTL
467 {
468     LONG x;
469     LONG y;
470 } POINTL;
471
472 #define CONV_POINT16TO32(p16,p32) \
473             ((p32)->x = (INT)(p16)->x, (p32)->y = (INT)(p16)->y)
474 #define CONV_POINT32TO16(p32,p16) \
475             ((p16)->x = (INT16)(p32)->x, (p16)->y = (INT16)(p32)->y)
476
477 #define MAKEPOINT16(l) (*((POINT16 *)&(l)))
478
479 /* The POINTS structure */
480
481 typedef struct tagPOINTS
482 {
483         SHORT x;
484         SHORT y;
485 } POINTS, *PPOINTS, *LPPOINTS;
486
487
488 #define MAKEPOINTS(l)  (*((POINTS *)&(l)))
489
490
491 /* The RECT structure */
492 typedef struct tagRECT
493 {
494     INT  left;
495     INT  top;
496     INT  right;
497     INT  bottom;
498 } RECT, *PRECT, *LPRECT;
499 typedef const RECT *LPCRECT;
500
501
502 typedef struct tagRECTL
503 {
504     LONG left;
505     LONG top;  
506     LONG right;
507     LONG bottom;
508 } RECTL, *PRECTL, *LPRECTL;
509
510 typedef const RECTL *LPCRECTL;
511
512 #define CONV_RECT16TO32(r16,r32) \
513     ((r32)->left  = (INT)(r16)->left,  (r32)->top    = (INT)(r16)->top, \
514      (r32)->right = (INT)(r16)->right, (r32)->bottom = (INT)(r16)->bottom)
515 #define CONV_RECT32TO16(r32,r16) \
516     ((r16)->left  = (INT16)(r32)->left,  (r16)->top    = (INT16)(r32)->top, \
517      (r16)->right = (INT16)(r32)->right, (r16)->bottom = (INT16)(r32)->bottom)
518
519 #ifdef __cplusplus
520 }
521 #endif
522
523 #endif /* __WINE_WINDEF_H */