Leaked source code of windows server 2003
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.

285 lines
13 KiB

  1. /**************************************************************************\
  2. * Module Name: ntsend.h
  3. *
  4. * Copyright (c) 1985 - 1999, Microsoft Corporation
  5. *
  6. * client-side macros for kernel-mode
  7. *
  8. * 03-21-95 JimA Created.
  9. \**************************************************************************/
  10. /*
  11. * The BEGINCALLCONNECT macro ensures that the thread is set up correctly.
  12. */
  13. #define BEGINCALLCONNECT() \
  14. { \
  15. ULONG_PTR retval; \
  16. { \
  17. if (NtCurrentTeb()->Win32ThreadInfo == NULL) { \
  18. if (!USERTHREADCONNECT()) { \
  19. MSGERROR(); \
  20. } \
  21. }
  22. /*
  23. * Use this macro if you don't need to access shared memory.
  24. */
  25. #define BEGINCALL() \
  26. { \
  27. ULONG_PTR retval; \
  28. {
  29. #define BEGINCALL_CLASSV() \
  30. { \
  31. ULONG_PTR retval; \
  32. TCHAR ClassNameVer[MAX_ATOM_LEN]; \
  33. LPTSTR lpClassNameVer; \
  34. BOOL bRegistered = FALSE; \
  35. PACTIVATION_CONTEXT lpActivationContext = NULL; \
  36. LPWSTR lpDllName = NULL; \
  37. { \
  38. lpClassNameVer = (LPTSTR)ClassNameToVersion((LPCWSTR)pszClassName, \
  39. (LPWSTR)ClassNameVer, &lpDllName, &lpActivationContext, IS_ANSI); \
  40. if (lpClassNameVer == NULL) { \
  41. RIPMSG0(RIP_WARNING, "Couldn't resolve class name"); \
  42. MSGERROR(); \
  43. }
  44. #define BEGINCALLVOID() \
  45. {
  46. #define ERRORTRAP(error) \
  47. goto cleanup; \
  48. } \
  49. goto errorexit; \
  50. errorexit: \
  51. retval = (ULONG_PTR)error; \
  52. cleanup:
  53. #define ERRORTRAPVOID() \
  54. goto errorexit; \
  55. errorexit:
  56. #define ENDCALL(type) \
  57. return (type)retval; \
  58. }
  59. #define ENDCALLVOID() \
  60. return; \
  61. }
  62. #define MSGERROR() goto errorexit
  63. #define MSGERRORCODE(code) { \
  64. RIPERR0(code, RIP_WARNING, "Unspecified error"); \
  65. goto errorexit; }
  66. #define MSGNTERRORCODE(code) { \
  67. RIPNTERR0(code, RIP_WARNING, "Unspecified error"); \
  68. goto errorexit; }
  69. #define MESSAGECALL(api) \
  70. LRESULT api( \
  71. HWND hwnd, \
  72. UINT msg, \
  73. WPARAM wParam, \
  74. LPARAM lParam, \
  75. ULONG_PTR xParam, \
  76. DWORD xpfnProc, \
  77. BOOL bAnsi)
  78. /*
  79. * Copy optional string/Ordinal where if hiword is FF/FFFF then new WORD is a
  80. * resource oridinal ID
  81. * Sources is Unicode
  82. */
  83. #define OrdinalLPSTR(src) (MAKELONG(0xFFFF,((*(DWORD UNALIGNED *)src) >> 8)))
  84. #define OrdinalLPSTRW(src) (MAKELONG(0xFFFF,((*(DWORD UNALIGNED *)src) >> 8)))
  85. #define OrdinalLPWSTR(src) (*(DWORD UNALIGNED *)src)
  86. #define OrdinalLPWSTRA(src) (*(DWORD UNALIGNED *)((PBYTE)src + 1))
  87. /*
  88. * Ansi->Unicode macros
  89. */
  90. #define COPYLPSTRW(pinstr, psz) \
  91. if (!RtlCaptureAnsiString((pinstr), (LPCSTR)(psz), TRUE)) \
  92. MSGERROR();
  93. #define COPYLPSTRIDW(pinstr, psz) \
  94. if (IS_PTR(psz)) { \
  95. if (!RtlCaptureAnsiString((pinstr), (LPCSTR)(psz), TRUE)) \
  96. MSGERROR(); \
  97. } \
  98. else { \
  99. (pinstr)->fAllocated = FALSE; \
  100. (pinstr)->pstr = &(pinstr)->strCapture; \
  101. (pinstr)->strCapture.Length = \
  102. (pinstr)->strCapture.MaximumLength = 0; \
  103. (pinstr)->strCapture.Buffer = (LPWSTR)(psz); \
  104. }
  105. #define COPYLPSTRIDOPTW COPYLPSTRIDW
  106. #define COPYLPSTROPTW COPYLPSTRW
  107. #define LARGECOPYLPSTRW(pinstr, psz) \
  108. if(!RtlCaptureLargeAnsiString((pinstr), (LPCSTR)(psz), TRUE)) \
  109. MSGERROR();
  110. #define LARGECOPYLPSTROPTW LARGECOPYLPSTRW
  111. #define LARGECOPYLPSTRORDINALOPTW(pinstr, psz) \
  112. (pinstr)->pstr = &(pinstr)->strCapture; \
  113. (pinstr)->fAllocated = FALSE; \
  114. if (psz) { \
  115. if (*(LPBYTE)(psz) != 0xff) { \
  116. if (!RtlCaptureLargeAnsiString((pinstr), (LPCSTR)(psz), TRUE)) \
  117. MSGERROR(); \
  118. } else { \
  119. (pinstr)->strCapture.Length = \
  120. (pinstr)->strCapture.MaximumLength = sizeof(DWORD); \
  121. dwOrdinal = OrdinalLPSTRW(psz); \
  122. (pinstr)->strCapture.Buffer = (LPWSTR)&dwOrdinal; \
  123. } \
  124. } else { \
  125. (pinstr)->strCapture.Length = \
  126. (pinstr)->strCapture.MaximumLength = 0; \
  127. (pinstr)->strCapture.Buffer = NULL; \
  128. }
  129. #define FIRSTCOPYLPSTRW(pinstr, psz) \
  130. if (!RtlCaptureAnsiString((pinstr), (LPCSTR)(psz), FALSE)) \
  131. MSGERROR();
  132. #define FIRSTCOPYLPSTRIDW(pinstr, psz) \
  133. if (IS_PTR(psz)) { \
  134. if (!RtlCaptureAnsiString((pinstr), (LPCSTR)(psz), FALSE)) \
  135. MSGERROR(); \
  136. } else { \
  137. (pinstr)->fAllocated = FALSE; \
  138. (pinstr)->pstr = &(pinstr)->strCapture; \
  139. (pinstr)->strCapture.Length = \
  140. (pinstr)->strCapture.MaximumLength = 0; \
  141. (pinstr)->strCapture.Buffer = (LPWSTR)(psz); \
  142. }
  143. #define FIRSTCOPYLPSTRIDOPTW FIRSTCOPYLPSTRIDW
  144. #define FIRSTCOPYLPSTROPTW FIRSTCOPYLPSTRW
  145. #define FIRSTLARGECOPYLPSTRW(pinstr, psz) \
  146. if (!RtlCaptureLargeAnsiString((pinstr), (LPCSTR)(psz), FALSE)) \
  147. MSGERROR();
  148. #define FIRSTLARGECOPYLPSTROPTW FIRSTLARGECOPYLPSTRW
  149. #define FIRSTLARGECOPYLPSTRORDINALOPTW(pinstr, psz) \
  150. (pinstr)->pstr = &(pinstr)->strCapture; \
  151. (pinstr)->fAllocated = FALSE; \
  152. if (psz) { \
  153. if (*(LPBYTE)(psz) != 0xff) { \
  154. if (!RtlCaptureLargeAnsiString((pinstr), (LPCSTR)(psz), FALSE)) \
  155. MSGERROR(); \
  156. } else { \
  157. (pinstr)->strCapture.Length = \
  158. (pinstr)->strCapture.MaximumLength = sizeof(DWORD); \
  159. dwOrdinal = OrdinalLPSTRW(psz); \
  160. (pinstr)->strCapture.Buffer = (LPWSTR)&dwOrdinal; \
  161. } \
  162. } else { \
  163. (pinstr)->strCapture.Length = \
  164. (pinstr)->strCapture.MaximumLength = 0; \
  165. (pinstr)->strCapture.Buffer = NULL; \
  166. }
  167. #define CLEANUPLPSTRW(instr) \
  168. if (instr.fAllocated) \
  169. UserLocalFree(KPVOID_TO_PVOID(instr.strCapture.Buffer));
  170. /*
  171. * Unicode->Unicode macros
  172. */
  173. #define COPYLPWSTR(pinstr, psz) \
  174. (pinstr)->fAllocated = FALSE; \
  175. (pinstr)->pstr = &(pinstr)->strCapture; \
  176. RtlInitUnicodeString(&(pinstr)->strCapture, (psz));
  177. #define COPYLPWSTRID(pinstr, psz) \
  178. (pinstr)->fAllocated = FALSE; \
  179. (pinstr)->pstr = &(pinstr)->strCapture; \
  180. if (IS_PTR(psz)) \
  181. RtlInitUnicodeString(&(pinstr)->strCapture, (psz)); \
  182. else { \
  183. (pinstr)->strCapture.Length = \
  184. (pinstr)->strCapture.MaximumLength = 0; \
  185. (pinstr)->strCapture.Buffer = (LPWSTR)(psz); \
  186. }
  187. #define COPYLPWSTRIDOPT COPYLPWSTRID
  188. #define COPYLPWSTROPT COPYLPWSTR
  189. #define LARGECOPYLPWSTR(pinstr, psz) \
  190. (pinstr)->fAllocated = FALSE; \
  191. (pinstr)->pstr = &(pinstr)->strCapture; \
  192. RtlInitLargeUnicodeString(&(pinstr)->strCapture, (psz), (UINT)-1);
  193. #define LARGECOPYLPWSTROPT LARGECOPYLPWSTR
  194. #define LARGECOPYLPWSTRORDINALOPT(pinstr, psz) \
  195. (pinstr)->fAllocated = FALSE; \
  196. (pinstr)->pstr = &(pinstr)->strCapture; \
  197. if (psz) { \
  198. if (*(LPWORD)(psz) != 0xffff) \
  199. RtlInitLargeUnicodeString(&(pinstr)->strCapture, (psz), (UINT)-1); \
  200. else { \
  201. (pinstr)->strCapture.Length = \
  202. (pinstr)->strCapture.MaximumLength = sizeof(DWORD); \
  203. dwOrdinal = OrdinalLPWSTR(psz); \
  204. (pinstr)->strCapture.Buffer = (LPWSTR)&dwOrdinal; \
  205. } \
  206. } else { \
  207. (pinstr)->strCapture.Length = \
  208. (pinstr)->strCapture.MaximumLength = 0; \
  209. (pinstr)->strCapture.Buffer = NULL; \
  210. }
  211. #define FIRSTCOPYLPWSTR COPYLPWSTR
  212. #define FIRSTCOPYLPWSTRID COPYLPWSTRID
  213. #define FIRSTCOPYLPWSTRIDOPT COPYLPWSTRIDOPT
  214. #define FIRSTCOPYLPWSTROPT COPYLPWSTROPT
  215. #define FIRSTLARGECOPYLPWSTR LARGECOPYLPWSTR
  216. #define FIRSTLARGECOPYLPWSTROPT LARGECOPYLPWSTROPT
  217. #define FIRSTLARGECOPYLPWSTRORDINALOPT LARGECOPYLPWSTRORDINALOPT
  218. #define CLEANUPLPWSTR(instr)
  219. /*
  220. * Type-neutral macros
  221. */
  222. #ifdef UNICODE
  223. #define COPYLPTSTR COPYLPWSTR
  224. #define COPYLPTSTRID COPYLPWSTRID
  225. #define COPYLPTSTRIDOPT COPYLPWSTRIDOPT
  226. #define COPYLPTSTROPT COPYLPWSTROPT
  227. #define FIRSTCOPYLPTSTR COPYLPWSTR
  228. #define FIRSTCOPYLPTSTRID COPYLPWSTRID
  229. #define FIRSTCOPYLPTSTRIDOPT COPYLPWSTRIDOPT
  230. #define LARGECOPYLPTSTR LARGECOPYLPWSTR
  231. #define LARGECOPYLPTSTROPT LARGECOPYLPWSTROPT
  232. #define FIRSTLARGECOPYLPTSTROPT LARGECOPYLPWSTROPT
  233. #define CLEANUPLPTSTR CLEANUPLPWSTR
  234. #else
  235. #define COPYLPTSTR COPYLPSTRW
  236. #define COPYLPTSTRID COPYLPSTRIDW
  237. #define COPYLPTSTRIDOPT COPYLPSTRIDOPTW
  238. #define COPYLPTSTROPT COPYLPSTROPTW
  239. #define FIRSTCOPYLPTSTR COPYLPSTRW
  240. #define FIRSTCOPYLPTSTRID COPYLPSTRIDW
  241. #define FIRSTCOPYLPTSTRIDOPT COPYLPSTRIDOPTW
  242. #define LARGECOPYLPTSTR LARGECOPYLPSTRW
  243. #define LARGECOPYLPTSTROPT LARGECOPYLPSTROPTW
  244. #define FIRSTLARGECOPYLPTSTROPT LARGECOPYLPSTROPTW
  245. #define CLEANUPLPTSTR CLEANUPLPSTRW
  246. #endif