Debian Codegraph @

Source/Platform.h

raw
1 /*
2 * Platform.h
3 *
4 * This file is a part of NSIS.
5 *
6 * Copyright (C) 1999-2026 Nullsoft and Contributors
7 *
8 * Licensed under the zlib/libpng license (the "License");
9 * you may not use this file except in compliance with the License.
10 *
11 * Licence details can be found in the file COPYING.
12 *
13 * This software is provided 'as-is', without any express or implied
14 * warranty.
15 *
16 * Unicode support by Jim Park -- 08/13/2007
17 */
18
19 #ifndef ___PLATFORM__H___
20 #define ___PLATFORM__H___
21
22 // some definitions for non Win32 platforms were taken from MinGW's free Win32 library
23
24
25 #if defined(__cplusplus) && defined(MAKENSIS) && (!defined(_MSC_VER) || _MSC_VER > 1200)
26 template<class T> class NSISCHARTYPE{ T _c; public: NSISCHARTYPE(){} NSISCHARTYPE(T c):_c(c){} operator T()const{ return _c; } };
27 typedef NSISCHARTYPE<unsigned short> WINWCHAR; // WINWCHAR is always UTF16LE and should not be passed to wcs* functions
28 #else
29 typedef unsigned short WINWCHAR;
30 #endif
31
32
33 // includes
34
35 #include "tchar.h"
36
37 #ifdef _WIN32
38 #include <windows.h>
39 #include <commctrl.h>
40 #include <shellapi.h>
41 #include <shlwapi.h>
42 #include <shlobj.h>
43 #else
44 # include <stdint.h>
45 # ifndef EXEHEAD
46 # include <string.h>
47 # include <stdlib.h>
48 # endif
49 // basic types
50 typedef uint8_t BYTE, *PBYTE, *LPBYTE;
51 typedef uint16_t WORD, *LPWORD;
52 typedef uint32_t DWORD, *LPDWORD;
53 typedef int16_t SHORT;
54 typedef uint16_t USHORT;
55 typedef uint32_t UINT;
56 typedef uint32_t UINT32;
57 typedef int32_t INT;
58 typedef int32_t INT32;
59 typedef int32_t LONG;
60 typedef uint32_t ULONG;
61 typedef int64_t INT64, LARGE_INTEGER;
62 typedef uint64_t UINT64, ULARGE_INTEGER;
63 typedef intptr_t INT_PTR;
64 typedef uintptr_t UINT_PTR;
65 typedef int BOOL, *LPBOOL;
66 typedef short VARIANT_BOOL;
67 typedef void VOID;
68 typedef void *LPVOID;
69 typedef char CHAR, *PCHAR, *LPCH, *PCH, *NPSTR, *LPSTR, *PSTR;
70 typedef unsigned char UCHAR;
71 typedef const char *LPCCH, *PCSTR, *LPCSTR;
72 typedef unsigned short WCHAR, OLECHAR, *PWCHAR, *LPWCH, *PWCH, *NWPSTR, *LPWSTR, *PWSTR, *BSTR;
73 typedef const unsigned short *LPCWCH, *PCWCH, *LPCWSTR, *PCWSTR, *LPCOLESTR;
74 #ifndef _tctime
75 #define _tctime _wctime
76 #else
77 #define _tctime ctime
78 #endif
79 // basic stuff
80 typedef void * HANDLE;
81 typedef HANDLE HWND;
82 typedef HANDLE HMODULE;
83 typedef unsigned long HKEY;
84 // some gdi
85 typedef DWORD COLORREF;
86 typedef HANDLE HBRUSH;
87 // bool
88 # define FALSE 0
89 # define TRUE 1
90 // more
91 typedef WORD LANGID;
92 // ULONGLONG
93 #ifdef __GNUC__
94 #define _HAVE_INT64
95 #define _INTEGRAL_MAX_BITS 64
96 #undef __int64
97 #define __int64 long long
98 #elif defined(__WATCOMC__) && (defined(_INTEGRAL_MAX_BITS) && _INTEGRAL_MAX_BITS >= 64 )
99 #define _HAVE_INT64
100 #endif /* __GNUC__/__WATCOMC */
101 #if defined(_HAVE_INT64) || (defined(_INTEGRAL_MAX_BITS) && _INTEGRAL_MAX_BITS >= 64)
102 typedef __int64 LONGLONG;
103 typedef unsigned __int64 DWORDLONG;
104 #else
105 typedef double LONGLONG,DWORDLONG;
106 #endif
107 typedef LONGLONG *PLONGLONG;
108 typedef DWORDLONG *PDWORDLONG;
109 typedef DWORDLONG ULONGLONG,*PULONGLONG;
110
111 // function mapping
112 #define _strdup strdup
113 #define _snprintf snprintf
114 #define _vsnprintf vsnprintf
115
116 #endif // ?WIN32
117
118 #ifndef INT_MAX
119 #include <limits.h>
120 #endif
121
122
123 // mingw32 and w64-mingw32 do not define ULONG_PTR
124 // but rather declare ULONG_PTR via typedef (see basetsd.h)
125 #if !defined(__MINGW32__) && !defined(ULONG_PTR)
126 # ifndef _WIN64
127 # define ULONG_PTR unsigned long
128 # endif
129 #endif
130
131 #ifdef __cplusplus
132 #include <algorithm>
133 #if defined(_MSC_VER) && ( _MSC_VER <= 1200 || (defined(_MIN) && _MSC_FULL_VER >= 140000000 && _MSC_FULL_VER <= 140040310) )
134 #define STD_MIN std::_MIN
135 #define STD_MAX std::_MAX
136 #else
137 #define STD_MIN (std::min) // This works even when windows.h defines min/max
138 #define STD_MAX (std::max)
139 #endif
140 #endif
141
142 #ifndef COUNTOF
143 #define COUNTOF(a) (sizeof(a)/sizeof(a[0]))
144 #endif
145
146 #ifndef __BIG_ENDIAN__
147 # define FIX_ENDIAN_INT64(x) (x)
148 # define FIX_ENDIAN_INT32_INPLACE(x) ((void)(x))
149 # define FIX_ENDIAN_INT32(x) (x)
150 # define FIX_ENDIAN_INT16_INPLACE(x) ((void)(x))
151 # define FIX_ENDIAN_INT16(x) (x)
152 # define BE2HE32(x) SWAP_ENDIAN_INT32(x)
153 #else
154 # define FIX_ENDIAN_INT64(x) SWAP_ENDIAN_INT64(x)
155 # define FIX_ENDIAN_INT32_INPLACE(x) ((x) = SWAP_ENDIAN_INT32(x))
156 # define FIX_ENDIAN_INT32(x) SWAP_ENDIAN_INT32(x)
157 # define FIX_ENDIAN_INT16_INPLACE(x) ((x) = SWAP_ENDIAN_INT16(x))
158 # define FIX_ENDIAN_INT16(x) SWAP_ENDIAN_INT16(x)
159 # define BE2HE32(x) (x)
160 #endif
161 #define SWAP_ENDIAN_INT64(x) ( \
162 (((x)&0xFF00000000000000) >> 56) | \
163 (((x)&0x00FF000000000000) >> 40) | \
164 (((x)&0x0000FF0000000000) >> 24) | \
165 (((x)&0x000000FF00000000) >> 8) | \
166 (((x)&0x00000000FF000000) << 8) | \
167 (((x)&0x0000000000FF0000) << 24) | \
168 (((x)&0x000000000000FF00) << 40) | \
169 (((x)&0x00000000000000FF) << 56) )
170 #define SWAP_ENDIAN_INT32(x) ( \
171 (((x)&0xFF000000) >> 24) | \
172 (((x)&0x00FF0000) >> 8) | \
173 (((x)&0x0000FF00) << 8) | \
174 (((x)&0x000000FF) << 24) )
175 #define SWAP_ENDIAN_INT16(x) ( \
176 (((x)&0xFF00) >> 8) | \
177 (((x)&0x00FF) << 8) )
178
179 // script path separator
180
181 # define PATH_SEPARATOR_STR _T("\\")
182 # define PATH_SEPARATOR_C _T('\\')
183
184 // system specific characters
185
186 #ifdef _WIN32
187 # define PLATFORM_PATH_SEPARATOR_STR _T("\\")
188 # define PLATFORM_PATH_SEPARATOR_C _T('\\')
189 # define OPT_STR _T("/")
190 # define OPT_C _T('/')
191 # define IS_OPT(a) (a[0]==OPT_C||a[0]==_T('-'))
192 #else
193 # define PLATFORM_PATH_SEPARATOR_STR _T("/")
194 # define PLATFORM_PATH_SEPARATOR_C _T('/')
195 # define OPT_STR _T("-")
196 # define OPT_C _T('-')
197 # define IS_OPT(a) (a[0]==OPT_C)
198 #endif
199
200 // attributes
201
202 #ifdef _MSC_VER
203 # define FORCE_INLINE __forceinline
204 #else
205 # ifdef __GNUC__
206 # if __GNUC__ < 3
207 # define FORCE_INLINE inline
208 # else
209 # define FORCE_INLINE inline __attribute__ ((always_inline))
210 # endif
211 # else
212 # define FORCE_INLINE inline
213 # endif
214 #endif
215
216 #if defined(__GNUC__)
217 #define UNUSED __attribute__((unused))
218 #else
219 #define UNUSED
220 #endif
221
222 // macros
223
224 #ifndef _WIN32
225 # ifndef FIELD_OFFSET
226 # define FIELD_OFFSET(t,f) ((UINT_PTR)&(((t*)0)->f))
227 # endif
228 # ifndef MAKEINTRESOURCEA
229 # define MAKEINTRESOURCEA(i) ((LPSTR)((ULONG_PTR)((WORD)(ULONG_PTR)(i))))
230 # endif
231 # ifndef MAKEINTRESOURCEW
232 # define MAKEINTRESOURCEW(i) ((LPWSTR)((ULONG_PTR)((WORD)(ULONG_PTR)(i))))
233 # endif
234 # ifndef MAKEINTRESOURCE
235 # ifdef _UNICODE
236 # define MAKEINTRESOURCE MAKEINTRESOURCEW
237 # else
238 # define MAKEINTRESOURCE MAKEINTRESOURCEA
239 # endif
240 # endif
241 # ifndef IMAGE_FIRST_SECTION
242 # define IMAGE_FIRST_SECTION(h) ( PIMAGE_SECTION_HEADER( (ULONG_PTR) h + \
243 FIELD_OFFSET(IMAGE_NT_HEADERS, OptionalHeader) + \
244 FIX_ENDIAN_INT16(PIMAGE_NT_HEADERS(h)->FileHeader.SizeOfOptionalHeader) ) )
245 # endif
246 # ifndef RGB
247 # define RGB(r,g,b) ((DWORD)(((BYTE)(r)|((WORD)(g)<<8))|(((DWORD)(BYTE)(b))<<16)))
248 # endif
249 # ifndef LOBYTE
250 # define LOBYTE(w) ((BYTE)(w))
251 # define HIBYTE(w) ((BYTE)(((WORD)(w)>>8)&0xFF))
252 # endif
253 # ifndef MAKEWORD
254 # define MAKEWORD(a,b) ((WORD)(((BYTE)(a))|(((WORD)((BYTE)(b)))<<8)))
255 # endif
256 # ifndef MAKELONG
257 # define MAKELONG(a,b) ((DWORD)(((WORD)(a))|(((DWORD)((WORD)(b)))<<16)))
258 # endif
259 #endif
260 #ifndef IS_INTRESOURCE
261 # define IS_INTRESOURCE(_r) (((ULONG_PTR)(_r) >> 16) == 0)
262 #endif
263
264 #ifndef IS_HIGH_SURROGATE
265 # define IS_HIGH_SURROGATE(wch) (((wch) >= 0xd800) && ((wch) <= 0xdbff))
266 #endif
267
268 // functions
269
270 // Anders: MSVC's swprintf is non standard, use _snwprintf when you really mean swprintf
271 #if !defined(_MSC_VER) && !defined(__MINGW32__) && !defined(_snwprintf)
272 # define _snwprintf swprintf // (wchar_t*,size_t,const wchar_t*,...)
273 #endif
274 #ifndef _WIN32
275 # define _vsnwprintf vswprintf // (wchar_t*,size_t,const wchar_t*,va_list)
276 #endif
277
278 // Jim Park: These str functions will probably never be encountered with all my
279 // Unicode changes. And if they were used, these would probably be wrong.
280 #ifndef _WIN32
281 # define stricmp strcasecmp
282 # define strcmpi strcasecmp
283 # define strnicmp strncasecmp
284 # define CopyMemory memcpy
285 # define ZeroMemory(x, y) memset(x, 0, y)
286 #endif
287
288 #ifndef _WIN64
289 # ifndef GCLP_HICON
290 # define GCLP_HICON GCL_HICON
291 # define SetClassLongPtr SetClassLong
292 # endif
293 #endif
294
295 // defines
296
297 #ifndef MEM_LARGE_PAGES
298 # define MEM_LARGE_PAGES 0x20000000
299 #endif
300
301 #ifndef WC_NO_BEST_FIT_CHARS
302 # define WC_NO_BEST_FIT_CHARS 0x400
303 #endif
304
305 #ifndef IDC_HAND
306 # define IDC_HAND MAKEINTRESOURCE(32649)
307 #endif
308
309 #ifndef BIF_NEWDIALOGSTYLE
310 # define BIF_NEWDIALOGSTYLE 0x0040
311 #endif
312
313 #ifndef TVITEM
314 # define TVITEM TV_ITEM
315 #endif
316
317 #ifndef TVM_SETITEMHEIGHT
318 # define TVM_SETITEMHEIGHT (TV_FIRST + 27)
319 #endif
320
321 #ifndef TVM_GETITEMHEIGHT
322 # define TVM_GETITEMHEIGHT (TV_FIRST + 28)
323 #endif
324
325 #ifndef LVS_EX_LABELTIP
326 # define LVS_EX_LABELTIP 0x00004000
327 #endif
328
329 #ifndef EXEHEAD
330 # ifndef SF_TEXT
331 # define SF_TEXT 0x0001
332 # endif
333 # ifndef SF_RTF
334 # define SF_RTF 0x0002
335 # endif
336 # ifndef SF_UNICODE
337 # define SF_UNICODE 0x0010
338 # endif
339 #endif
340
341 #ifdef __GNUC__
342 # undef INVALID_FILE_ATTRIBUTES
343 #endif
344 #ifndef INVALID_FILE_ATTRIBUTES
345 # define INVALID_FILE_ATTRIBUTES ((DWORD) -1)
346 #endif
347
348 // shell folders
349
350 #ifdef _WIN32
351 # include <shlobj.h>
352 #endif
353
354 #ifndef CSIDL_FLAG_CREATE
355 # define CSIDL_FLAG_CREATE 0x8000
356 #endif
357
358 #ifndef CSIDL_PROGRAMS
359 # define CSIDL_PROGRAMS 0x2
360 #endif
361 #ifndef CSIDL_COMMON_PROGRAMS
362 # define CSIDL_COMMON_PROGRAMS 0x17
363 #endif
364 #ifndef CSIDL_PRINTERS
365 # define CSIDL_PRINTERS 0x4
366 #endif
367 #ifndef CSIDL_PERSONAL
368 # define CSIDL_PERSONAL 0x5
369 #endif
370 #ifndef CSIDL_COMMON_DOCUMENTS
371 # define CSIDL_COMMON_DOCUMENTS 0x2E
372 #endif
373 #ifndef CSIDL_FAVORITES
374 # define CSIDL_FAVORITES 0x6
375 #endif
376 #ifndef CSIDL_COMMON_FAVORITES
377 # define CSIDL_COMMON_FAVORITES 0x1F
378 #endif
379 #ifndef CSIDL_STARTUP
380 # define CSIDL_STARTUP 0x7
381 #endif
382 #ifndef CSIDL_COMMON_STARTUP
383 # define CSIDL_COMMON_STARTUP 0x18
384 #endif
385 #ifndef CSIDL_RECENT
386 # define CSIDL_RECENT 0x8
387 #endif
388 #ifndef CSIDL_SENDTO
389 # define CSIDL_SENDTO 0x9
390 #endif
391 #ifndef CSIDL_STARTMENU
392 # define CSIDL_STARTMENU 0xB
393 #endif
394 #ifndef CSIDL_COMMON_STARTMENU
395 # define CSIDL_COMMON_STARTMENU 0x16
396 #endif
397 #ifndef CSIDL_DESKTOPDIRECTORY
398 # define CSIDL_DESKTOPDIRECTORY 0x10
399 #endif
400 #ifndef CSIDL_COMMON_DESKTOPDIRECTORY
401 # define CSIDL_COMMON_DESKTOPDIRECTORY 0x19
402 #endif
403 #ifndef CSIDL_NETHOOD
404 # define CSIDL_NETHOOD 0x13
405 #endif
406 #ifndef CSIDL_FONTS
407 # define CSIDL_FONTS 0x14
408 #endif
409 #ifndef CSIDL_TEMPLATES
410 # define CSIDL_TEMPLATES 0x15
411 #endif
412 #ifndef CSIDL_COMMON_TEMPLATES
413 # define CSIDL_COMMON_TEMPLATES 0x2D
414 #endif
415 #ifndef CSIDL_APPDATA
416 # define CSIDL_APPDATA 0x1A
417 #endif
418 #ifndef CSIDL_COMMON_APPDATA
419 # define CSIDL_COMMON_APPDATA 0x23
420 #endif
421 #ifndef CSIDL_LOCAL_APPDATA
422 # define CSIDL_LOCAL_APPDATA 0x1C
423 #endif
424 #ifndef CSIDL_PRINTHOOD
425 # define CSIDL_PRINTHOOD 0x1B
426 #endif
427 #ifndef CSIDL_ALTSTARTUP
428 # define CSIDL_ALTSTARTUP 0x1D
429 #endif
430 #ifndef CSIDL_COMMON_ALTSTARTUP
431 # define CSIDL_COMMON_ALTSTARTUP 0x1E
432 #endif
433 #ifndef CSIDL_INTERNET_CACHE
434 # define CSIDL_INTERNET_CACHE 0x20
435 #endif
436 #ifndef CSIDL_COOKIES
437 # define CSIDL_COOKIES 0x21
438 #endif
439 #ifndef CSIDL_HISTORY
440 # define CSIDL_HISTORY 0x22
441 #endif
442 #ifndef CSIDL_WINDOWS
443 # define CSIDL_WINDOWS 0x24
444 #endif
445 #ifndef CSIDL_SYSTEM
446 # define CSIDL_SYSTEM 0x25
447 #endif
448 #ifndef CSIDL_PROGRAM_FILES
449 # define CSIDL_PROGRAM_FILES 0x26
450 #endif
451 #ifndef CSIDL_PROGRAM_FILES_COMMON
452 # define CSIDL_PROGRAM_FILES_COMMON 0x2B
453 #endif
454 #ifndef CSIDL_MYPICTURES
455 # define CSIDL_MYPICTURES 0x27
456 #endif
457 #ifndef CSIDL_COMMON_PICTURES
458 # define CSIDL_COMMON_PICTURES 0x36
459 #endif
460 #ifndef CSIDL_PROFILE
461 # define CSIDL_PROFILE 0x28
462 #endif
463 #ifndef CSIDL_ADMINTOOLS
464 # define CSIDL_ADMINTOOLS 0x30
465 #endif
466 #ifndef CSIDL_COMMON_ADMINTOOLS
467 # define CSIDL_COMMON_ADMINTOOLS 0x2F
468 #endif
469 #ifndef CSIDL_MYMUSIC
470 # define CSIDL_MYMUSIC 0xD
471 #endif
472 #ifndef CSIDL_COMMON_MUSIC
473 # define CSIDL_COMMON_MUSIC 0x35
474 #endif
475 #ifndef CSIDL_MYVIDEO
476 # define CSIDL_MYVIDEO 0xE
477 #endif
478 #ifndef CSIDL_COMMON_VIDEO
479 # define CSIDL_COMMON_VIDEO 0x37
480 #endif
481 #ifndef CSIDL_RESOURCES
482 # define CSIDL_RESOURCES 0x38
483 #endif
484 #ifndef CSIDL_RESOURCES_LOCALIZED
485 # define CSIDL_RESOURCES_LOCALIZED 0x39
486 #endif
487 #ifndef CSIDL_CDBURN_AREA
488 # define CSIDL_CDBURN_AREA 0x3B
489 #endif
490
491 #ifndef SHGFP_TYPE_CURRENT
492 #define SHGFP_TYPE_CURRENT 0
493 #endif
494
495 // other shell stuff
496
497 #ifndef SHACF_FILESYSTEM
498 # define SHACF_FILESYSTEM 1
499 #endif
500
501 #ifndef SEE_MASK_NOCLOSEPROCESS
502 #define SEE_MASK_NOCLOSEPROCESS 0x00000040
503 #define SEE_MASK_FLAG_NO_UI 0x00000400
504 #define SEE_MASK_FLAG_DDEWAIT 0x00000100
505 #endif
506
507 // other stuff
508
509 #ifndef CP_ACP
510 # define CP_ACP 0
511 # define CP_OEMCP 1
512 #endif
513 #ifndef CP_UTF8
514 # define CP_UTF8 65001
515 #endif
516
517 #ifndef COLOR_BTNFACE
518 # define COLOR_BTNFACE 15
519 #endif
520 #ifndef COLOR_WINDOW
521 # define COLOR_WINDOW 5
522 #endif
523 #ifndef COLOR_HOTLIGHT
524 # define COLOR_HOTLIGHT 26
525 #endif
526
527 // resources
528
529 #ifndef RT_CURSOR
530 # define RT_CURSOR MAKEINTRESOURCE(1)
531 # define RT_GROUP_CURSOR MAKEINTRESOURCE(1 + 11)
532 #endif
533 #ifndef RT_BITMAP
534 # define RT_BITMAP MAKEINTRESOURCE(2)
535 #endif
536 #ifndef RT_ICON
537 # define RT_ICON MAKEINTRESOURCE(3)
538 #endif
539 #ifndef RT_DIALOG
540 # define RT_DIALOG MAKEINTRESOURCE(5)
541 #endif
542 #ifndef RT_GROUP_ICON
543 # define RT_GROUP_ICON MAKEINTRESOURCE(3 + 11)
544 #endif
545 #ifndef RT_VERSION
546 # define RT_VERSION MAKEINTRESOURCE(16)
547 #endif
548
549 // version
550
551 #ifndef VS_FILE_INFO
552 # define VS_FILE_INFO RT_VERSION
553 #endif
554 #ifndef VS_VERSION_INFO
555 # define VS_VERSION_INFO 1
556 #endif
557 #ifndef VS_FFI_SIGNATURE
558 # define VS_FFI_SIGNATURE 0xFEEF04BD
559 #endif
560
561 // message box
562
563 #ifndef MB_OK
564 # define MB_OK 0
565 # define MB_OKCANCEL 1
566 # define MB_ABORTRETRYIGNORE 2
567 # define MB_YESNOCANCEL 3
568 # define MB_YESNO 4
569 # define MB_RETRYCANCEL 5
570 # define MB_DEFBUTTON1 0
571 # define MB_DEFBUTTON2 256
572 # define MB_DEFBUTTON3 512
573 # define MB_DEFBUTTON4 768
574 # define MB_ICONSTOP 16
575 # define MB_ICONQUESTION 32
576 # define MB_ICONEXCLAMATION 48
577 # define MB_ICONINFORMATION 64
578 # define MB_USERICON 128
579 # define MB_SETFOREGROUND 0x10000
580 # define MB_TOPMOST 0x40000
581 # define MB_RIGHT 0x80000
582 # define MB_RTLREADING 0x100000
583 #endif
584
585 #ifndef IDOK
586 # define IDOK 1
587 # define IDCANCEL 2
588 # define IDABORT 3
589 # define IDRETRY 4
590 # define IDIGNORE 5
591 # define IDYES 6
592 # define IDNO 7
593 #endif
594
595 // window styles
596
597 #ifndef _WIN32
598 # define WS_CHILD 0x40000000
599 # define WS_VISIBLE 0x10000000
600
601 # define BS_CHECKBOX 2
602 # define BS_LEFT 256
603 # define BS_LEFTTEXT 32
604 # define BS_RADIOBUTTON 4
605 # define BS_RIGHT 512
606 # define BS_USERBUTTON 8
607
608 # define ES_LEFT 0
609 # define ES_CENTER 1
610 # define ES_RIGHT 2
611
612 # define SS_BITMAP 14
613 # define SS_CENTER 1
614 # define SS_CENTERIMAGE 512
615 # define SS_ICON 3
616 # define SS_LEFT 0
617 # define SS_LEFTNOWORDWRAP 0xc
618 # define SS_RIGHT 2
619 # define SS_RIGHTJUST 0x400
620 # define SS_USERITEM 10
621 # define SS_TYPEMASK 0x0000001FL
622
623 # define DS_FIXEDSYS 8
624 # define DS_SETFONT 64
625
626 # define WS_EX_RIGHT 0x1000
627 # define WS_EX_RIGHTSCROLLBAR 0
628 # define WS_EX_RTLREADING 0x2000
629 # define WS_EX_LEFTSCROLLBAR 0x4000
630 # define WS_EX_LAYOUTRTL 0x00400000
631
632 # define TVS_RTLREADING 64
633
634 # define PBS_SMOOTH 1
635 #endif
636
637 #ifndef SS_REALSIZECONTROL
638 # define SS_REALSIZECONTROL 0x0040
639 #endif
640
641 #ifndef DS_SHELLFONT
642 # define DS_SHELLFONT (DS_SETFONT | DS_FIXEDSYS)
643 #endif
644
645 // brush styles
646
647 #ifndef BS_SOLID
648 # define BS_SOLID 0
649 #endif
650 #ifndef BS_NULL
651 # define BS_NULL 1
652 #endif
653
654 // reg
655 #ifndef HKEY_CLASSES_ROOT
656 # define HKEY_CLASSES_ROOT ((HKEY)0x80000000)
657 # define HKEY_CURRENT_USER ((HKEY)0x80000001)
658 # define HKEY_LOCAL_MACHINE ((HKEY)0x80000002)
659 # define HKEY_USERS ((HKEY)0x80000003)
660 # define HKEY_PERFORMANCE_DATA ((HKEY)0x80000004)
661 # define HKEY_CURRENT_CONFIG ((HKEY)0x80000005)
662 # define HKEY_DYN_DATA ((HKEY)0x80000006)
663 #endif
664
665 #ifndef KEY_WOW64_32KEY
666 # define KEY_WOW64_32KEY 0x200
667 #endif
668 #ifndef KEY_WOW64_64KEY
669 # define KEY_WOW64_64KEY 0x100
670 #endif
671
672 #ifndef REG_SZ
673 # define REG_NONE 0
674 # define REG_SZ 1
675 # define REG_EXPAND_SZ 2
676 # define REG_BINARY 3
677 # define REG_DWORD 4
678 # define REG_MULTI_SZ 7
679 #endif
680
681 // show modes
682
683 #ifndef SW_SHOWNORMAL
684 # define SW_HIDE 0
685 # define SW_SHOWNORMAL 1
686 # define SW_SHOWMINIMIZED 2
687 # define SW_SHOWMAXIMIZED 3
688 # define SW_SHOWNOACTIVATE 4
689 # define SW_SHOW 5
690 # define SW_SHOWMINNOACTIVE 7
691 # define SW_SHOWNA 8
692 # define SW_RESTORE 9
693 # define SW_SHOWDEFAULT 10
694 #endif
695
696 // hotkeys
697
698 #ifndef HOTKEYF_SHIFT
699 # define HOTKEYF_SHIFT 1
700 # define HOTKEYF_CONTROL 2
701 # define HOTKEYF_ALT 4
702 # define HOTKEYF_EXT 8
703 #endif
704
705 // vk
706 #ifndef VK_F1
707 # define VK_F1 0x70
708 #endif
709
710 // gdi
711
712 #ifndef OPAQUE
713 # define OPAQUE 2
714 #endif
715 #ifndef TRANSPARENT
716 # define TRANSPARENT 1
717 #endif
718 #ifndef LF_FACESIZE
719 # define LF_FACESIZE 32
720 #endif
721 #ifndef FW_NORMAL
722 # define FW_NORMAL 400
723 #endif
724 #ifndef FW_BOLD
725 # define FW_BOLD 700
726 #endif
727 #ifndef DEFAULT_CHARSET
728 # define DEFAULT_CHARSET 1
729 #endif
730 #ifndef SHIFTJIS_CHARSET
731 # define SHIFTJIS_CHARSET 128
732 #endif
733 #ifndef OUT_DEFAULT_PRECIS
734 # define OUT_DEFAULT_PRECIS 0
735 #endif
736 #ifndef CLIP_DEFAULT_PRECIS
737 # define CLIP_DEFAULT_PRECIS 0
738 #endif
739 #ifndef DEFAULT_QUALITY
740 # define DEFAULT_QUALITY 0
741 #endif
742 #ifndef DEFAULT_PITCH
743 # define DEFAULT_PITCH 0
744 #endif
745
746 // file ops
747
748 #ifndef FOF_SILENT
749 # define FOF_SILENT 4
750 # define FOF_NOCONFIRMATION 16
751 # define FOF_FILESONLY 128
752 # define FOF_SIMPLEPROGRESS 256
753 # define FOF_NOCONFIRMMKDIR 512
754 #endif
755 #ifndef FOF_NOERRORUI
756 # define FOF_NOERRORUI 0x0400
757 #endif
758
759 // file attribs
760
761 #ifndef FILE_ATTRIBUTE_READONLY
762 # define FILE_ATTRIBUTE_READONLY 0x00000001
763 # define FILE_ATTRIBUTE_HIDDEN 0x00000002
764 # define FILE_ATTRIBUTE_SYSTEM 0x00000004
765 # define FILE_ATTRIBUTE_ARCHIVE 0x00000020
766 # define FILE_ATTRIBUTE_NORMAL 0x00000080
767 # define FILE_ATTRIBUTE_TEMPORARY 0x00000100
768 # define FILE_ATTRIBUTE_OFFLINE 0x00001000
769 #endif
770 #ifndef FILE_ATTRIBUTE_NOT_CONTENT_INDEXED
771 # define FILE_ATTRIBUTE_NOT_CONTENT_INDEXED 0x002000
772 #endif
773
774
775 // fopen
776 #ifndef GENERIC_READ
777 # define GENERIC_READ 0x80000000
778 # define GENERIC_WRITE 0x40000000
779 #endif
780
781 #ifndef CREATE_NEW
782 # define CREATE_NEW 1
783 # define CREATE_ALWAYS 2
784 # define OPEN_EXISTING 3
785 # define OPEN_ALWAYS 4
786 #endif
787
788 // fseek
789
790 #ifndef FILE_BEGIN
791 # define FILE_BEGIN 0
792 # define FILE_CURRENT 1
793 # define FILE_END 2
794 #endif
795
796 // PE
797
798 #ifndef _WIN32
799 # define IMAGE_NUMBEROF_DIRECTORY_ENTRIES 16
800 # ifndef __BIG_ENDIAN__
801 # define IMAGE_DOS_SIGNATURE 0x5A4D
802 # define IMAGE_NT_SIGNATURE 0x00004550
803 # else
804 # define IMAGE_DOS_SIGNATURE 0x4D5A
805 # define IMAGE_NT_SIGNATURE 0x50450000
806 # endif
807 # define IMAGE_FILE_DLL 8192
808 # define IMAGE_DIRECTORY_ENTRY_EXPORT 0
809 # define IMAGE_SIZEOF_SHORT_NAME 8
810 #endif
811 #ifndef IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE
812 #define IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE 0x0040 // ASLR
813 #endif
814 #ifndef IMAGE_DLLCHARACTERISTICS_NX_COMPAT
815 #define IMAGE_DLLCHARACTERISTICS_NX_COMPAT 0x0100 // DEP
816 #endif
817 #ifndef IMAGE_DLLCHARACTERISTICS_NO_SEH
818 #define IMAGE_DLLCHARACTERISTICS_NO_SEH 0x0400
819 #endif
820 #ifndef IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE
821 #define IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE 0x8000
822 #endif
823 #ifndef IMAGE_DLLCHARACTERISTICS_HIGH_ENTROPY_VA
824 #define IMAGE_DLLCHARACTERISTICS_HIGH_ENTROPY_VA 0x0020 // HEASLR
825 #endif
826
827 // structures
828
829 #ifndef _WIN32
830 typedef struct _LOGFONT {
831 LONG lfHeight;
832 LONG lfWidth;
833 LONG lfEscapement;
834 LONG lfOrientation;
835 LONG lfWeight;
836 BYTE lfItalic;
837 BYTE lfUnderline;
838 BYTE lfStrikeOut;
839 BYTE lfCharSet;
840 BYTE lfOutPrecision;
841 BYTE lfClipPrecision;
842 BYTE lfQuality;
843 BYTE lfPitchAndFamily;
844 TCHAR lfFaceName[LF_FACESIZE];
845 } LOGFONT;
846 # pragma pack(2)
847 typedef struct _IMAGE_DOS_HEADER {
848 WORD e_magic;
849 WORD e_cblp;
850 WORD e_cp;
851 WORD e_crlc;
852 WORD e_cparhdr;
853 WORD e_minalloc;
854 WORD e_maxalloc;
855 WORD e_ss;
856 WORD e_sp;
857 WORD e_csum;
858 WORD e_ip;
859 WORD e_cs;
860 WORD e_lfarlc;
861 WORD e_ovno;
862 WORD e_res[4];
863 WORD e_oemid;
864 WORD e_oeminfo;
865 WORD e_res2[10];
866 LONG e_lfanew;
867 } IMAGE_DOS_HEADER,*PIMAGE_DOS_HEADER;
868 # pragma pack()
869 # pragma pack(4)
870 typedef struct _IMAGE_FILE_HEADER {
871 WORD Machine;
872 WORD NumberOfSections;
873 DWORD TimeDateStamp;
874 DWORD PointerToSymbolTable;
875 DWORD NumberOfSymbols;
876 WORD SizeOfOptionalHeader;
877 WORD Characteristics;
878 } IMAGE_FILE_HEADER, *PIMAGE_FILE_HEADER;
879 typedef struct _IMAGE_DATA_DIRECTORY {
880 DWORD VirtualAddress;
881 DWORD Size;
882 } IMAGE_DATA_DIRECTORY,*PIMAGE_DATA_DIRECTORY;
883 typedef struct _IMAGE_OPTIONAL_HEADER32 {
884 WORD Magic;
885 BYTE MajorLinkerVersion;
886 BYTE MinorLinkerVersion;
887 DWORD SizeOfCode;
888 DWORD SizeOfInitializedData;
889 DWORD SizeOfUninitializedData;
890 DWORD AddressOfEntryPoint;
891 DWORD BaseOfCode;
892 DWORD BaseOfData;
893 DWORD ImageBase;
894 DWORD SectionAlignment;
895 DWORD FileAlignment;
896 WORD MajorOperatingSystemVersion;
897 WORD MinorOperatingSystemVersion;
898 WORD MajorImageVersion;
899 WORD MinorImageVersion;
900 WORD MajorSubsystemVersion;
901 WORD MinorSubsystemVersion;
902 DWORD Reserved1;
903 DWORD SizeOfImage;
904 DWORD SizeOfHeaders;
905 DWORD CheckSum;
906 WORD Subsystem;
907 WORD DllCharacteristics;
908 DWORD SizeOfStackReserve;
909 DWORD SizeOfStackCommit;
910 DWORD SizeOfHeapReserve;
911 DWORD SizeOfHeapCommit;
912 DWORD LoaderFlags;
913 DWORD NumberOfRvaAndSizes;
914 IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES];
915 } IMAGE_OPTIONAL_HEADER32,*PIMAGE_OPTIONAL_HEADER32;
916 typedef struct _IMAGE_OPTIONAL_HEADER64 {
917 WORD Magic;
918 BYTE MajorLinkerVersion;
919 BYTE MinorLinkerVersion;
920 DWORD SizeOfCode;
921 DWORD SizeOfInitializedData;
922 DWORD SizeOfUninitializedData;
923 DWORD AddressOfEntryPoint;
924 DWORD BaseOfCode;
925 ULONGLONG ImageBase;
926 DWORD SectionAlignment;
927 DWORD FileAlignment;
928 WORD MajorOperatingSystemVersion;
929 WORD MinorOperatingSystemVersion;
930 WORD MajorImageVersion;
931 WORD MinorImageVersion;
932 WORD MajorSubsystemVersion;
933 WORD MinorSubsystemVersion;
934 DWORD Win32VersionValue;
935 DWORD SizeOfImage;
936 DWORD SizeOfHeaders;
937 DWORD CheckSum;
938 WORD Subsystem;
939 WORD DllCharacteristics;
940 ULONGLONG SizeOfStackReserve;
941 ULONGLONG SizeOfStackCommit;
942 ULONGLONG SizeOfHeapReserve;
943 ULONGLONG SizeOfHeapCommit;
944 DWORD LoaderFlags;
945 DWORD NumberOfRvaAndSizes;
946 IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES];
947 } IMAGE_OPTIONAL_HEADER64,*PIMAGE_OPTIONAL_HEADER64;
948 typedef struct _IMAGE_NT_HEADERS32 {
949 DWORD Signature;
950 IMAGE_FILE_HEADER FileHeader;
951 IMAGE_OPTIONAL_HEADER32 OptionalHeader;
952 } IMAGE_NT_HEADERS32,*PIMAGE_NT_HEADERS32;
953 typedef struct _IMAGE_NT_HEADERS64 {
954 DWORD Signature;
955 IMAGE_FILE_HEADER FileHeader;
956 IMAGE_OPTIONAL_HEADER64 OptionalHeader;
957 } IMAGE_NT_HEADERS64,*PIMAGE_NT_HEADERS64;
958 #ifdef _WIN64
959 typedef IMAGE_OPTIONAL_HEADER64 IMAGE_OPTIONAL_HEADER;
960 typedef PIMAGE_OPTIONAL_HEADER64 PIMAGE_OPTIONAL_HEADER;
961 typedef IMAGE_NT_HEADERS64 IMAGE_NT_HEADERS;
962 typedef PIMAGE_NT_HEADERS64 PIMAGE_NT_HEADERS;
963 #else
964 typedef IMAGE_OPTIONAL_HEADER32 IMAGE_OPTIONAL_HEADER;
965 typedef PIMAGE_OPTIONAL_HEADER32 PIMAGE_OPTIONAL_HEADER;
966 typedef IMAGE_NT_HEADERS32 IMAGE_NT_HEADERS;
967 typedef PIMAGE_NT_HEADERS32 PIMAGE_NT_HEADERS;
968 #endif
969 #ifndef __BIG_ENDIAN__
970 # define IMAGE_NT_OPTIONAL_HDR32_MAGIC 0x010b
971 # define IMAGE_NT_OPTIONAL_HDR64_MAGIC 0x020b
972 #else
973 # define IMAGE_NT_OPTIONAL_HDR32_MAGIC 0x0b01
974 # define IMAGE_NT_OPTIONAL_HDR64_MAGIC 0x0b02
975 #endif
976 typedef struct _IMAGE_SECTION_HEADER {
977 BYTE Name[IMAGE_SIZEOF_SHORT_NAME];
978 union {
979 DWORD PhysicalAddress;
980 DWORD VirtualSize;
981 } Misc;
982 DWORD VirtualAddress;
983 DWORD SizeOfRawData;
984 DWORD PointerToRawData;
985 DWORD PointerToRelocations;
986 DWORD PointerToLinenumbers;
987 WORD NumberOfRelocations;
988 WORD NumberOfLinenumbers;
989 DWORD Characteristics;
990 } IMAGE_SECTION_HEADER,*PIMAGE_SECTION_HEADER;
991 typedef struct _IMAGE_EXPORT_DIRECTORY {
992 DWORD Characteristics;
993 DWORD TimeDateStamp;
994 WORD MajorVersion;
995 WORD MinorVersion;
996 DWORD Name;
997 DWORD Base;
998 DWORD NumberOfFunctions;
999 DWORD NumberOfNames;
1000 DWORD AddressOfFunctions;
1001 DWORD AddressOfNames;
1002 DWORD AddressOfNameOrdinals;
1003 } IMAGE_EXPORT_DIRECTORY,*PIMAGE_EXPORT_DIRECTORY;
1004 typedef struct tagVS_FIXEDFILEINFO {
1005 DWORD dwSignature;
1006 DWORD dwStrucVersion;
1007 DWORD dwFileVersionMS;
1008 DWORD dwFileVersionLS;
1009 DWORD dwProductVersionMS;
1010 DWORD dwProductVersionLS;
1011 DWORD dwFileFlagsMask;
1012 DWORD dwFileFlags;
1013 DWORD dwFileOS;
1014 DWORD dwFileType;
1015 DWORD dwFileSubtype;
1016 DWORD dwFileDateMS;
1017 DWORD dwFileDateLS;
1018 } VS_FIXEDFILEINFO;
1019 # pragma pack()
1020 #endif
1021
1022
1023 // MinGW does not implement the unicode CRT startup functions
1024 #if (defined(_UNICODE) && defined(_WIN32)) && defined(__MINGW32__)
1025 # define NSIS_ENTRYPOINT_TMAIN \
1026 int _tmain(int argc,WCHAR**argv); \
1027 EXTERN_C int main(int ac,char**cav) { \
1028 WCHAR**av=CommandLineToArgvW(GetCommandLineW(),&ac); \
1029 if (!av) { \
1030 _tprintf(_T("wmain: Error %u\n"),ac = GetLastError()); \
1031 return ac; \
1032 } \
1033 ac = _tmain(ac,av); \
1034 /*LEAK: LocalFree(av);*/ \
1035 return ac; \
1036 }
1037 # define NSIS_ENTRYPOINT_SIMPLEGUI \
1038 int WINAPI _tWinMain(HINSTANCE hI,HINSTANCE hOld,LPTSTR cl,int sc); \
1039 EXTERN_C int WINAPI WinMain(HINSTANCE hI,HINSTANCE hOld,char*cl,int sc) \
1040 {return _tWinMain(hI,0,0,sc);}
1041 # ifdef __cplusplus
1042 # define NSIS_ENTRYPOINT_GUINOCRT \
1043 EXTERN_C void NSISWinMainNOCRT(); \
1044 int WINAPI WinMain(HINSTANCE hI,HINSTANCE hOld,char*cl,int sc) \
1045 {NSISWinMainNOCRT();return 0;}
1046 # endif
1047 #endif
1048 #ifndef NSIS_ENTRYPOINT_TMAIN
1049 # define NSIS_ENTRYPOINT_TMAIN
1050 #endif
1051 #ifndef NSIS_ENTRYPOINT_SIMPLEGUI // _tWinMain with valid hInstance, calls ExitProcess
1052 # define NSIS_ENTRYPOINT_SIMPLEGUI
1053 #endif
1054 #ifndef NSIS_ENTRYPOINT_GUINOCRT
1055 # define NSIS_ENTRYPOINT_GUINOCRT
1056 #endif
1057
1058
1059 #if defined(__clang__) && defined(__cplusplus) && __cplusplus < 201103L
1060 # define NSIS_CXX_THROWSPEC(throwspec) throw(throwspec) // Use exception specifications to avoid operator new missing-exception-spec warning
1061 #else
1062 # define NSIS_CXX_THROWSPEC(ignoredthrowspec) // Ignore c++ exception specifications
1063 #endif
1064 #if defined(__cplusplus) && __cplusplus >= 201103L
1065 # define NSIS_CXX_NOEXCEPT() noexcept(true)
1066 #else
1067 # define NSIS_CXX_NOEXCEPT() throw() // Can't specialize __declspec(nothrow) because MSVC requires it before the function name
1068 #endif
1069 #if defined(_MSC_VER) && _MSC_VER <= 1200
1070 # define NSIS_CXX_TYPENAME // VC6 can't handle typename in some places but GCC requires it
1071 #else
1072 # define NSIS_CXX_TYPENAME typename
1073 #endif
1074 #define BUGBUG64TRUNCATE(cast,xpr) ( (cast) (xpr) )
1075
1076 /*
1077 _tprintf on Windows/MSVCRT treats %s as TCHAR* and on POSIX %s is always char*!
1078 Always use our NPRI* (NsisPRInt*[Narrow|Wide]) defines in format strings when calling
1079 functions from tchar.h (Similar to the way <inttypes.h> works)
1080
1081 Example: _tprintf(_T("%") NPRIs _T(" %") NPRIws _T("\n"), _T("Hello"), L"World");
1082 */
1083 #ifdef _WIN32
1084 # define NPRIs _T("s")
1085 # define NPRIns _T("hs")
1086 # define NPRIws _T("ls") // ws also works, not sure which is most compatible
1087 # ifndef _WIN64
1088 # define NPRIp _T(".8x")
1089 # define NPRIpN ".8x"
1090 # endif
1091 #else // !_WIN32
1092 # define NPRIns _T("s")
1093 # define NPRIws _T("ls")
1094 # ifdef _UNICODE
1095 # define NPRIs _T("ls")
1096 # else // !_UNICODE
1097 # define NPRIs _T("s")
1098 # endif // ~_UNICODE
1099 #endif // ~_WIN32
1100 #ifndef NPRIp
1101 # define NPRIp _T("p")
1102 # define NPRIpN "p"
1103 #endif
1104
1105
1106 // Disable deprecated warnings (Windows SDK for Windows 8.1)
1107 #ifdef _MSC_VER
1108 #if _MSC_VER >= 1500
1109 FORCEINLINE DWORD NoDepr_GetVersion() { __pragma(warning(push))__pragma(warning(disable:4996)) DWORD r = GetVersion(); __pragma(warning(pop)) return r; }
1110 #define GetVersion NoDepr_GetVersion
1111 FORCEINLINE BOOL NoDepr_GetVersionExA(OSVERSIONINFOA*p) { __pragma(warning(push))__pragma(warning(disable:4996)) BOOL r = GetVersionExA(p); __pragma(warning(pop)) return r; }
1112 #define GetVersionExA NoDepr_GetVersionExA
1113 FORCEINLINE BOOL NoDepr_GetVersionExW(OSVERSIONINFOW*p) { __pragma(warning(push))__pragma(warning(disable:4996)) BOOL r = GetVersionExW(p); __pragma(warning(pop)) return r; }
1114 #define GetVersionExW NoDepr_GetVersionExW
1115 #endif //~ _MSC_VER >= 1500
1116 #endif //~ _MSC_VER
1117
1118
1119 #ifdef __cplusplus
1120 namespace STL
1121 {
1122 template<class M> struct mapped_type { typedef typename M::value_type::second_type type; }; // VC6 uses referent_type and not mapped_type
1123 }
1124 #endif //~ __cplusplus
1125
1126 #endif // EOF