Windows NT 4.0 source code leak
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

412 lines
12 KiB

4 years ago
  1. /****************************************************************************
  2. *
  3. * Win32.h
  4. *
  5. * Windows 16/32 porting helper file
  6. *
  7. *
  8. ***************************************************************************/
  9. /**************************************************************************
  10. *
  11. * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
  12. * KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  13. * IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
  14. * PURPOSE.
  15. *
  16. * Copyright (c) 1992 - 1995 Microsoft Corporation. All Rights Reserved.
  17. *
  18. **************************************************************************/
  19. #ifndef INC_OLE2
  20. #define INC_OLE2
  21. #endif
  22. #ifndef INC_WIN32_H
  23. #define INC_WIN32_H // Protect against double inclusion of this file
  24. #if !defined(WIN32) && defined(_WIN32)
  25. #define WIN32
  26. #endif
  27. #if !defined(DEBUG) && defined(_DEBUG)
  28. #define DEBUG
  29. #endif
  30. #ifdef WIN32
  31. // Set up a single define to allow CHICAGO or NT (Daytona)
  32. // N.B. We CANNOT use WINVER <= 0x400 to determine if this is Chicago
  33. // or Daytona. Parts of the Daytona code use Common Controls. For this
  34. // to work WINVER is defined as 0x0400...
  35. // On the other hand, no Chicago code is compiled with UNICODE defined.
  36. #ifdef UNICODE
  37. #define DAYTONA
  38. #undef CHICAGO
  39. #else
  40. #ifndef CHICAGO
  41. #define CHICAGO
  42. #endif
  43. #undef DAYTONA
  44. #endif // UNICODE
  45. #ifndef RC_INVOKED
  46. #pragma warning(disable:4103)
  47. #endif
  48. #define _INC_OLE
  49. #else // 16 bit compilation - must be Chicago
  50. #ifndef CHICAGO
  51. #define CHICAGO
  52. #endif
  53. #endif // WIN32
  54. #if !defined(_INC_WINDOWS) || !defined(_WINDOWS)
  55. #include <windows.h>
  56. #include <windowsx.h>
  57. #if WINVER >= 0x400
  58. #include <winerror.h>
  59. #endif
  60. #include <mmsystem.h>
  61. #endif // INC_WINDOWS...
  62. #ifndef EXTERN_C
  63. #ifdef __cplusplus
  64. #define EXTERN_C extern "C"
  65. #else
  66. #define EXTERN_C extern
  67. #endif
  68. #endif
  69. // Not just for Daytona, things like mciavi define WINVER=0x30a
  70. #ifndef WS_EX_RIGHT
  71. #define WS_EX_RIGHT 0x00001000L // ;Internal 4.0
  72. #define WS_EX_LEFT 0x00000000L // ;Internal 4.0
  73. #define WS_EX_RTLREADING 0x00002000L // ;Internal 4.0
  74. #define WS_EX_LTRREADING 0x00000000L // ;Internal 4.0
  75. #define WS_EX_LEFTSCROLLBAR 0x00004000L // ;Internal 4.0
  76. #define WS_EX_RIGHTSCROLLBAR 0x00000000L // ;Internal 4.0
  77. #endif
  78. // Win 16 and Win 32 use different macros to turn code debugging on/off
  79. // Map the 16 bit version to the NT conventions.
  80. // In particular on NT, debug builds are identified by DBG==1 (and retail
  81. // with DBG==0), hence the NT only source uses #if DBG. Note: #ifdef DBG
  82. // is ALWAYS true on NT.
  83. // Chicago (and VFW 16 bit code) uses #ifdef DEBUG. The complex of
  84. // instructions below should ensure that whether this is Chicago or NT that
  85. // a debug build implies DEBUG defined and DBG==1
  86. // a retail build implies DEBUG NOT defined, and DBG==0
  87. #ifdef WIN32
  88. #ifndef DBG
  89. #ifdef DEBUG
  90. #define DBG 1
  91. #else
  92. #define DBG 0
  93. #endif
  94. #endif
  95. #undef DEBUG
  96. #if DBG
  97. #define DEBUG
  98. #define STATICFN
  99. #define STATICDT
  100. #else
  101. #define STATICFN static
  102. #define STATICDT static
  103. #endif
  104. #else // !WIN32
  105. #define STATICFN static
  106. #define STATICDT static
  107. #endif //WIN32
  108. #define FASTCALL __fastcall
  109. #define _FASTCALL __fastcall
  110. #if !defined NUMELMS
  111. #define NUMELMS(aa) (sizeof(aa)/sizeof((aa)[0]))
  112. #endif
  113. #ifdef WIN32
  114. /* --- Win32 version --------------------------------------------------- */
  115. #include <string.h>
  116. #include <memory.h>
  117. #undef CDECL
  118. #if defined(_MIPS_) || defined(_PPC_)
  119. #define __stdcall
  120. #define _stdcall
  121. #define _cdecl
  122. #define __cdecl
  123. #define CDECL
  124. #else
  125. #define CDECL _cdecl
  126. #endif
  127. //typedef BITMAPINFOHEADER FAR *LPBITMAPINFOHEADER;
  128. #define far
  129. #define _far
  130. #define __far
  131. #define HUGE_T
  132. #undef HUGE
  133. #define HUGE
  134. #define huge
  135. #define _huge
  136. #define __huge
  137. #define near
  138. #define _near
  139. #define __near
  140. #define _fastcall
  141. #define __fastcall
  142. #define _loadds
  143. #define __loadds
  144. #define _LOADDS
  145. #define LOADDS
  146. #define _export //should _export be blank?
  147. #define __export
  148. #define EXPORT
  149. #define _based(x)
  150. #define __based(x)
  151. #define _based32(x)
  152. #define __based32(x)
  153. #ifdef _X86_
  154. // __inline provides speed improvements for x86 platforms. Unfortunately
  155. // the MIPS compiler does not have inline support. Alpha is unknown, so
  156. // we do not assume and play it safe.
  157. #define INLINE __inline
  158. #define inline __inline
  159. #define _inline __inline
  160. #else
  161. #define INLINE
  162. #define inline
  163. #define _inline
  164. #define __inline
  165. #endif
  166. //typedef RGBQUAD FAR *LPRGBQUAD;
  167. //#ifdef DAYTONA
  168. //typedef LRESULT (*DRIVERPROC)(DWORD, HDRVR, UINT, WPARAM, LPARAM);
  169. //#endif
  170. // DriverProc is in the common win 32 sdk mmsystem.h.
  171. #define GetCurrentTask() (HTASK)GetCurrentThreadId()
  172. #define WF_PMODE 0x0001
  173. #define WF_CPU286 0x0002
  174. #define WF_CPU386 0x0004
  175. #define WF_CPU486 0x0008
  176. #define WF_80x87 0x0400
  177. #define WF_PAGING 0x0800
  178. #define GetWinFlags() (WF_PMODE|WF_CPU486|WF_PAGING|WF_80x87)
  179. //#define hmemcpy memcpy
  180. #define _fmemcpy memcpy
  181. #define _fmemset memset
  182. //#define lstrcpyn(dest, source, cb) ( strncpy(dest, source, cb), ((char *) dest) [cb - 1] = 0)
  183. //!!! should use LARGE_INTEGER stuff.
  184. #define muldiv32 MulDiv
  185. #define muldivru32(a,b,c) (long)(((double)(a) * (double)(b) + (double)((c)-1)) / (double)(c))
  186. #define muldivrd32(a,b,c) (long)(((double)(a) * (double)(b)) / (double)(c))
  187. #define IsTask(x) ((x) != 0)
  188. #define IsGDIObject(obj) (GetObjectType((HGDIOBJ)(obj)) != 0)
  189. #define SZCODEA CHAR
  190. #define SZCODE TCHAR
  191. typedef TCHAR * NPTSTR;
  192. #ifndef UNICODE
  193. // !!!!!!! need lstrcpyW, lstrlenW, wsprintfW, lstrcpynW for Chicago!
  194. #endif
  195. #else
  196. /* --- Win16 version --------------------------------------------------- */
  197. #include <string.h>
  198. #include <memory.h>
  199. #define SZCODEA SZCODE
  200. typedef char TCHAR;
  201. typedef WORD WCHAR;
  202. typedef NPSTR NPTSTR;
  203. typedef LPSTR LPTSTR;
  204. typedef LPSTR LPOLESTR;
  205. typedef LPCSTR LPCOLESTR;
  206. typedef char OLECHAR;
  207. typedef int INT;
  208. #define _LOADDS _loadds
  209. #define LOADDS _loadds
  210. #define EXPORT _export
  211. #define HUGE _huge
  212. #define DRIVERS_SECTION "Drivers"
  213. #define MCI_SECTION "MCI"
  214. #define MCIAVI_SECTION "MCIAVI"
  215. #define TEXT(sz) sz
  216. // stuff in muldiv32.asm
  217. EXTERN_C LONG FAR PASCAL muldiv32(LONG,LONG,LONG);
  218. EXTERN_C LONG FAR PASCAL muldivru32(LONG,LONG,LONG);
  219. EXTERN_C LONG FAR PASCAL muldivrd32(LONG,LONG,LONG);
  220. #define UNALIGNED
  221. #define INLINE __inline
  222. #define CharPrev AnsiPrev
  223. /*
  224. * define these so we can explicitly use Ansi or Unicode versions
  225. * in the NT code, and the standard entry point for Win16.
  226. */
  227. #define SetWindowTextA SetWindowText
  228. #define GetProfileStringA GetProfileString
  229. #define GetPrivateProfileStringA GetPrivateProfileString
  230. #define GetProfileIntA GetProfileInt
  231. #define GetModuleHandleA GetModuleHandle
  232. #define GetModuleFileNameA GetModuleFileName
  233. #define wvsprintfA wvsprintf
  234. #define wsprintfA wsprintf
  235. #define lstrcmpA lstrcmp
  236. #define lstrcmpiA lstrcmpi
  237. #define lstrcpyA lstrcpy
  238. #define lstrcatA lstrcat
  239. #define lstrlenA lstrlen
  240. #define LoadStringA LoadString
  241. #define LoadStringW LoadString
  242. #define OutputDebugStringA OutputDebugString
  243. #define MessageBoxA MessageBox
  244. // Needed for writing OLE-style code that builds 16/32....
  245. #define lstrcpyW lstrcpy
  246. #define lstrcpynW lstrcpyn
  247. #define lstrlenW lstrlen
  248. #define SZCODE char _based(_segname("_CODE"))
  249. #define LPCWSTR LPCSTR
  250. #define LPCTSTR LPCSTR
  251. #define LPWSTR LPSTR
  252. #define PTSTR PSTR
  253. /****** Alternate porting layer macros ****************************************/
  254. #ifndef GET_WPARAM
  255. /* USER MESSAGES: */
  256. #define GET_WPARAM(wp, lp) (wp)
  257. #define GET_LPARAM(wp, lp) (lp)
  258. #define GET_WM_ACTIVATE_STATE(wp, lp) (wp)
  259. #define GET_WM_ACTIVATE_FMINIMIZED(wp, lp) (BOOL)HIWORD(lp)
  260. #define GET_WM_ACTIVATE_HWND(wp, lp) (HWND)LOWORD(lp)
  261. #define GET_WM_ACTIVATE_MPS(s, fmin, hwnd) \
  262. (WPARAM)(s), MAKELONG(hwnd, fmin)
  263. #define GET_WM_CHARTOITEM_CHAR(wp, lp) (CHAR)(wp)
  264. #define GET_WM_CHARTOITEM_POS(wp, lp) HIWORD(lp)
  265. #define GET_WM_CHARTOITEM_HWND(wp, lp) (HWND)LOWORD(lp)
  266. #define GET_WM_CHARTOITEM_MPS(ch, pos, hwnd) \
  267. (WPARAM)(ch), MAKELONG(hwnd, pos)
  268. #define GET_WM_COMMAND_ID(wp, lp) (wp)
  269. #define GET_WM_COMMAND_HWND(wp, lp) (HWND)LOWORD(lp)
  270. #define GET_WM_COMMAND_CMD(wp, lp) HIWORD(lp)
  271. #define GET_WM_COMMAND_MPS(id, hwnd, cmd) \
  272. (WPARAM)(id), MAKELONG(hwnd, cmd)
  273. #define WM_CTLCOLORMSGBOX 0x0132
  274. #define WM_CTLCOLOREDIT 0x0133
  275. #define WM_CTLCOLORLISTBOX 0x0134
  276. #define WM_CTLCOLORBTN 0x0135
  277. #define WM_CTLCOLORDLG 0x0136
  278. #define WM_CTLCOLORSCROLLBAR 0x0137
  279. #define WM_CTLCOLORSTATIC 0x0138
  280. #define GET_WM_CTLCOLOR_HDC(wp, lp, msg) (HDC)(wp)
  281. #define GET_WM_CTLCOLOR_HWND(wp, lp, msg) (HWND)LOWORD(lp)
  282. #define GET_WM_CTLCOLOR_TYPE(wp, lp, msg) HIWORD(lp)
  283. #define GET_WM_CTLCOLOR_MPS(hdc, hwnd, type) \
  284. (WPARAM)(hdc), MAKELONG(hwnd, type)
  285. #define GET_WM_MENUSELECT_CMD(wp, lp) (wp)
  286. #define GET_WM_MENUSELECT_FLAGS(wp, lp) LOWORD(lp)
  287. #define GET_WM_MENUSELECT_HMENU(wp, lp) (HMENU)HIWORD(lp)
  288. #define GET_WM_MENUSELECT_MPS(cmd, f, hmenu) \
  289. (WPARAM)(cmd), MAKELONG(f, hmenu)
  290. // Note: the following are for interpreting MDIclient to MDI child messages.
  291. #define GET_WM_MDIACTIVATE_FACTIVATE(hwnd, wp, lp) (BOOL)(wp)
  292. #define GET_WM_MDIACTIVATE_HWNDDEACT(wp, lp) (HWND)HIWORD(lp)
  293. #define GET_WM_MDIACTIVATE_HWNDACTIVATE(wp, lp) (HWND)LOWORD(lp)
  294. // Note: the following is for sending to the MDI client window.
  295. #define GET_WM_MDIACTIVATE_MPS(f, hwndD, hwndA)\
  296. (WPARAM)(hwndA), 0
  297. #define GET_WM_MDISETMENU_MPS(hmenuF, hmenuW) 0, MAKELONG(hmenuF, hmenuW)
  298. #define GET_WM_MENUCHAR_CHAR(wp, lp) (CHAR)(wp)
  299. #define GET_WM_MENUCHAR_HMENU(wp, lp) (HMENU)LOWORD(lp)
  300. #define GET_WM_MENUCHAR_FMENU(wp, lp) (BOOL)HIWORD(lp)
  301. #define GET_WM_MENUCHAR_MPS(ch, hmenu, f) \
  302. (WPARAM)(ch), MAKELONG(hmenu, f)
  303. #define GET_WM_PARENTNOTIFY_MSG(wp, lp) (wp)
  304. #define GET_WM_PARENTNOTIFY_ID(wp, lp) HIWORD(lp)
  305. #define GET_WM_PARENTNOTIFY_HWNDCHILD(wp, lp) (HWND)LOWORD(lp)
  306. #define GET_WM_PARENTNOTIFY_X(wp, lp) (INT)LOWORD(lp)
  307. #define GET_WM_PARENTNOTIFY_Y(wp, lp) (INT)HIWORD(lp)
  308. #define GET_WM_PARENTNOTIFY_MPS(msg, id, hwnd) \
  309. (WPARAM)(msg), MAKELONG(hwnd, id)
  310. #define GET_WM_PARENTNOTIFY2_MPS(msg, x, y) \
  311. (WPARAM)(msg), MAKELONG(x, y)
  312. #define GET_WM_VKEYTOITEM_CODE(wp, lp) (wp)
  313. #define GET_WM_VKEYTOITEM_ITEM(wp, lp) (INT)HIWORD(lp)
  314. #define GET_WM_VKEYTOITEM_HWND(wp, lp) (HWND)LOWORD(lp)
  315. #define GET_WM_VKEYTOITEM_MPS(code, item, hwnd) \
  316. (WPARAM)(code), MAKELONG(hwnd, item)
  317. #define GET_EM_SETSEL_START(wp, lp) LOWORD(lp)
  318. #define GET_EM_SETSEL_END(wp, lp) HIWORD(lp)
  319. #define GET_EM_SETSEL_MPS(iStart, iEnd) \
  320. 0, MAKELONG(iStart, iEnd)
  321. #define GET_EM_LINESCROLL_MPS(vert, horz) \
  322. 0, MAKELONG(vert, horz)
  323. #define GET_WM_CHANGECBCHAIN_HWNDNEXT(wp, lp) (HWND)LOWORD(lp)
  324. #define GET_WM_HSCROLL_CODE(wp, lp) (wp)
  325. #define GET_WM_HSCROLL_POS(wp, lp) LOWORD(lp)
  326. #define GET_WM_HSCROLL_HWND(wp, lp) (HWND)HIWORD(lp)
  327. #define GET_WM_HSCROLL_MPS(code, pos, hwnd) \
  328. (WPARAM)(code), MAKELONG(pos, hwnd)
  329. #define GET_WM_VSCROLL_CODE(wp, lp) (wp)
  330. #define GET_WM_VSCROLL_POS(wp, lp) LOWORD(lp)
  331. #define GET_WM_VSCROLL_HWND(wp, lp) (HWND)HIWORD(lp)
  332. #define GET_WM_VSCROLL_MPS(code, pos, hwnd) \
  333. (WPARAM)(code), MAKELONG(pos, hwnd)
  334. #endif // !GET_WPARAM
  335. #endif // !WIN32
  336. #endif