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.

414 lines
13 KiB

  1. #pragma once
  2. #define ever (;;)
  3. void xGetOverlappedResult(
  4. HANDLE hFile,
  5. LPOVERLAPPED lpOverlapped,
  6. LPDWORD lpNumberOfBytesTransferred,
  7. BOOL bWait);
  8. HANDLE xCreateFile(
  9. PCTSTR pcszFileName, // file name
  10. DWORD dwDesiredAccess, // access mode
  11. DWORD dwShareMode, // share mode
  12. PSECURITY_ATTRIBUTES pSecurityAttributes, // SD
  13. DWORD dwCreationDisposition, // how to create
  14. DWORD dwFlagsAndAttributes, // file attributes
  15. HANDLE hTemplateFile); // handle to template file
  16. void xCloseHandle(
  17. HANDLE hObject); // handle to object
  18. BOOL xReadFile(
  19. HANDLE hFile, // handle to file
  20. PVOID pBuffer, // data buffer
  21. DWORD dwNumberOfBytesToRead, // number of bytes to read
  22. PDWORD pdwNumberOfBytesRead, // number of bytes read
  23. LPOVERLAPPED pOverlapped); // overlapped buffer
  24. void xReadFileWithAbort(
  25. HANDLE hFile, // handle to file
  26. PVOID pBuffer, // data buffer
  27. DWORD dwNumberOfBytesToRead, // number of bytes to read
  28. PDWORD pdwNumberOfBytesRead, // number of bytes read
  29. LPOVERLAPPED pOverlapped, // overlapped buffer
  30. HANDLE hAbort); // Handle to manual reset abort event
  31. BOOL xWriteFile(
  32. HANDLE hFile, // handle to file
  33. LPCVOID pBuffer, // data buffer
  34. DWORD dwNumberOfBytesToWrite, // number of bytes to write
  35. PDWORD pdwNumberOfBytesWritten, // number of bytes written
  36. LPOVERLAPPED pOverlapped); // overlapped buffer
  37. void xWriteFileWithAbort(
  38. HANDLE hFile, // handle to file
  39. LPCVOID pBuffer, // data buffer
  40. DWORD dwNumberOfBytesToWrite, // number of bytes to write
  41. PDWORD pdwNumberOfBytesWritten, // number of bytes written
  42. LPOVERLAPPED pOverlapped, // overlapped buffer
  43. HANDLE hAbort); // Handle to manual reset abort event
  44. void xGetCommState(
  45. HANDLE hFile, // handle to communications device
  46. LPDCB pDCB); // device-control block
  47. void xSetCommState(
  48. HANDLE hFile, // handle to communications device
  49. LPDCB pDCB); // device-control block
  50. void xGetCommTimeouts(
  51. HANDLE hFile, // handle to comm device
  52. LPCOMMTIMEOUTS pCommTimeouts); // time-out values
  53. void xSetCommTimeouts(
  54. HANDLE hFile, // handle to comm device
  55. LPCOMMTIMEOUTS pCommTimeouts); // time-out values
  56. void xSetCommMask(
  57. HANDLE hFile, // handle to communications device
  58. DWORD dwEvtMask); // mask that identifies enabled events
  59. void xGetCommMask(
  60. HANDLE hFile, // handle to communications device
  61. PDWORD pdwEvtMask); // mask that identifies enabled events
  62. BOOL xWaitCommEvent(
  63. HANDLE hFile, // handle to comm device
  64. PDWORD pdwEvtMask, // event type
  65. LPOVERLAPPED pOverlapped); // overlapped structure
  66. void xWaitCommEventWithAbort(
  67. HANDLE hFile, // handle to comm device
  68. PDWORD pdwEvtMask, // event type
  69. LPOVERLAPPED pOverlapped, // overlapped structure
  70. HANDLE hAbort); // Manual reset abort event
  71. void xEscapeCommFunction(
  72. HANDLE hFile, // handle to communications device
  73. DWORD dwFunc); // extended function to perform
  74. void xClearCommBreak(
  75. HANDLE hFile); // handle to communications device
  76. void xClearCommError(
  77. HANDLE hFile, // handle to communications device
  78. PDWORD pdwErrors, // error codes
  79. LPCOMSTAT pStat); // communications status
  80. void xBuildCommDCB(
  81. PCTSTR pcszDef, // device-control string
  82. LPDCB lpDCB); // device-control block
  83. void xTransmitCommChar(
  84. HANDLE hFile,
  85. char cChar);
  86. HANDLE xCreateThread(
  87. LPSECURITY_ATTRIBUTES lpThreadAttributes, // SD
  88. DWORD dwStackSize, // initial stack size
  89. LPTHREAD_START_ROUTINE lpStartAddress, // thread function
  90. LPVOID lpParameter, // thread argument
  91. DWORD dwCreationFlags, // creation option
  92. LPDWORD lpThreadId); // thread identifier
  93. void xTerminateThread(
  94. HANDLE hThread, // handle to thread
  95. DWORD dwExitCode); // exit code
  96. UINT_PTR xSetTimer(
  97. HWND hWnd, // handle to window
  98. UINT_PTR nIDEvent, // timer identifier
  99. UINT uElapse, // time-out value
  100. TIMERPROC lpTimerFunc); // timer procedure
  101. void xKillTimer(
  102. HWND hWnd, // handle to window
  103. UINT_PTR uIDEvent); // timer identifier
  104. void xFillConsoleOutputAttribute(
  105. HANDLE hConsoleOutput, // handle to screen buffer
  106. WORD wAttribute, // color attribute
  107. DWORD nLength, // number of cells
  108. COORD dwWriteCoord, // first coordinates
  109. LPDWORD lpNumberOfAttrsWritten // number of cells written
  110. );
  111. void xFillConsoleOutputCharacter(
  112. HANDLE hConsoleOutput, // handle to screen buffer
  113. TCHAR cCharacter, // character
  114. DWORD nLength, // number of cells
  115. COORD dwWriteCoord, // first coordinates
  116. LPDWORD lpNumberOfCharsWritten // number of cells written
  117. );
  118. void xGetConsoleScreenBufferInfo(
  119. HANDLE hConsoleOutput, // handle to screen buffer
  120. PCONSOLE_SCREEN_BUFFER_INFO lpConsoleScreenBufferInfo // screen buffer information
  121. );
  122. DWORD xGetConsoleTitle(
  123. LPTSTR lpConsoleTitle, // console title
  124. DWORD nSize // size of title buffer
  125. );
  126. COORD xGetLargestConsoleWindowSize(
  127. HANDLE hConsoleOutput // handle to screen buffer
  128. );
  129. HANDLE xGetStdHandle(
  130. DWORD nStdHandle = STD_OUTPUT_HANDLE);// Input, output or error device
  131. void xReadConsoleOutputAttribute(
  132. HANDLE hConsoleOutput, // handle to screen buffer
  133. LPWORD lpAttribute, // attributes buffer
  134. DWORD nLength, // number of cells to read
  135. COORD dwReadCoord, // coordinates of first cell
  136. LPDWORD lpNumberOfAttrsRead // number of cells read
  137. );
  138. void xReadConsoleOutputCharacter(
  139. HANDLE hConsoleOutput, // handle to screen buffer
  140. LPTSTR lpCharacter, // character buffer
  141. DWORD nLength, // number of cells to read
  142. COORD dwReadCoord, // coordinates of first cell
  143. LPDWORD lpNumberOfCharsRead // number of cells read
  144. );
  145. void xSetConsoleScreenBufferSize(
  146. HANDLE hConsoleOutput, // handle to screen buffer
  147. COORD dwSize // new screen buffer size
  148. );
  149. void xSetConsoleTextAttribute(
  150. HANDLE hConsoleOutput, // handle to screen buffer
  151. WORD wAttributes // text and background colors
  152. );
  153. void xSetConsoleTitle(
  154. LPCTSTR lpConsoleTitle // new console title
  155. );
  156. void xSetConsoleWindowInfo(
  157. HANDLE hConsoleOutput, // handle to screen buffer
  158. BOOL bAbsolute, // coordinate type
  159. CONST SMALL_RECT *lpConsoleWindow // window corners
  160. );
  161. void xWriteConsole(
  162. HANDLE hConsoleOutput, // handle to screen buffer
  163. CONST VOID *lpBuffer, // write buffer
  164. DWORD nNumberOfCharsToWrite, // number of characters to write
  165. LPDWORD lpNumberOfCharsWritten, // number of characters written
  166. LPVOID lpReserved // reserved
  167. );
  168. void xWriteConsoleOutputAttribute(
  169. HANDLE hConsoleOutput, // handle to screen buffer
  170. CONST WORD *lpAttribute, // write attributes
  171. DWORD nLength, // number of cells
  172. COORD dwWriteCoord, // first cell coordinates
  173. LPDWORD lpNumberOfAttrsWritten // number of cells written
  174. );
  175. void xWriteConsoleOutputCharacter(
  176. HANDLE hConsoleOutput, // handle to screen buffer
  177. LPCTSTR lpCharacter, // characters
  178. DWORD nLength, // number of characters to write
  179. COORD dwWriteCoord, // first cell coordinates
  180. LPDWORD lpNumberOfCharsWritten // number of cells written
  181. );
  182. HANDLE xCreateEvent(
  183. LPSECURITY_ATTRIBUTES lpEventAttributes, // SD
  184. BOOL bManualReset, // reset type
  185. BOOL bInitialState, // initial state
  186. LPCTSTR lpName); // object name
  187. void xSetEvent(
  188. HANDLE hEvent);
  189. void xResetEvent(
  190. HANDLE hEvent);
  191. DWORD xWaitForMultipleObjects(
  192. DWORD nCount, // number of handles in array
  193. CONST HANDLE *lpHandles, // object-handle array
  194. BOOL fWaitAll, // wait option
  195. DWORD dwMilliseconds); // time-out interval
  196. DWORD xWaitForSingleObject(
  197. HANDLE hHandle, // handle to object
  198. DWORD dwMilliseconds); // time-out interval
  199. PWSTR xMultiByteToWideChar(
  200. UINT CodePage, // code page
  201. DWORD dwFlags, // performance and mapping flags
  202. LPCSTR lpMultiByteStr); // wide-character string
  203. PSTR xWideCharToMultiByte(
  204. UINT CodePage, // code page
  205. DWORD dwFlags, // performance and mapping flags
  206. LPCWSTR lpWideCharStr); // wide-character string
  207. PWSTR xMakeWideChar(
  208. PTSTR pcszInput);
  209. PSTR xMakeMultiByte(
  210. PTSTR pcszInput);
  211. PTSTR xMakeDefaultChar(
  212. PWSTR pcszInput);
  213. PTSTR xMakeDefaultChar(
  214. PSTR pcszInput);
  215. DWORD xGetModuleFileName(
  216. HMODULE hModule, // handle to module
  217. LPTSTR lpFilename, // file name of module
  218. DWORD nSize // size of buffer
  219. );
  220. HANDLE xFindFirstFile(
  221. LPCTSTR lpFileName, // file name
  222. LPWIN32_FIND_DATA lpFindFileData);// data buffer
  223. BOOL xFindNextFile(
  224. HANDLE hFindFile, // search handle
  225. LPWIN32_FIND_DATA lpFindFileData);// data buffer
  226. HMODULE xLoadLibrary(
  227. LPCTSTR lpFileName); // file name of module
  228. BOOL xFreeLibrary(
  229. HMODULE hModule); // handle to DLL module
  230. FARPROC xGetProcAddress(
  231. HMODULE hModule,
  232. LPCSTR lpProcName);
  233. HANDLE xCreateMutex(
  234. LPSECURITY_ATTRIBUTES lpMutexAttributes, // SD
  235. BOOL bInitialOwner, // initial owner
  236. LPCTSTR lpName); // object name
  237. void xReleaseMutex(
  238. HANDLE hMutex);
  239. PTSTR xFormatMessage(
  240. DWORD dwFlags, // source and processing options
  241. LPCVOID lpSource, // message source
  242. DWORD dwMessageId, // message identifier
  243. DWORD dwLanguageId, // language identifier
  244. LPTSTR lpBuffer, // message buffer
  245. DWORD nSize, // maximum size of message buffer
  246. va_list *Arguments); // array of message inserts
  247. class CFindFile
  248. {
  249. public:
  250. CFindFile() :
  251. m_hFind(INVALID_HANDLE_VALUE) {}
  252. ~CFindFile();
  253. public:
  254. BOOL First(PCTSTR pcszFileName);
  255. BOOL Next();
  256. PWIN32_FIND_DATA Found();
  257. protected:
  258. HANDLE m_hFind;
  259. WIN32_FIND_DATA m_FindData;
  260. };
  261. template<
  262. class _Ty,
  263. void* _cf = CloseHandle,
  264. _Ty _inv = INVALID_HANDLE_VALUE>
  265. class auto_generic_handle
  266. {
  267. public:
  268. explicit auto_generic_handle(_Ty hValue = _inv) :
  269. _handle(hValue), _owner(hValue!=_inv) {}
  270. auto_generic_handle(const auto_generic_handle<_Ty,_cf,_inv>& _Y)
  271. : _owner(_Y._owner), _handle(_Y.release()) {}
  272. ~auto_generic_handle()
  273. {
  274. autoclose();
  275. }
  276. _Ty get() const
  277. {
  278. return _handle;
  279. }
  280. _Ty release() const
  281. {
  282. _owner = FALSE;
  283. return get();
  284. }
  285. void close()
  286. {
  287. if (_handle!=_inv)
  288. {
  289. ((auto_handle_closeproc)_cf)(_handle);
  290. _handle = _inv;
  291. }
  292. _owner = FALSE;
  293. }
  294. operator const _Ty () const
  295. {
  296. return _handle;
  297. }
  298. protected:
  299. void autoclose()
  300. {
  301. if (_owner)
  302. {
  303. close();
  304. }
  305. }
  306. auto_generic_handle<_Ty,_cf,_inv>& operator = (const auto_generic_handle<_Ty,_cf,_inv>& _Y)
  307. {
  308. if (this!=&_Y) // Ignore all self assignments
  309. {
  310. if (_handle!=_Y.get())
  311. {
  312. if (_owner)
  313. {
  314. close();
  315. }
  316. _owner = _Y._owner;
  317. }
  318. else if (_Y._owner)
  319. {
  320. _owner = TRUE;
  321. }
  322. _handle = _Y.release();
  323. }
  324. return *this;
  325. }
  326. private:
  327. //
  328. // We can only specialize this template to operate on handles that have
  329. // a close function taking one parameter (the handle) and returning BOOL.
  330. //
  331. typedef BOOL (WINAPI *auto_handle_closeproc)(_Ty);
  332. _Ty _handle;
  333. BOOL _owner;
  334. };
  335. typedef auto_generic_handle<HMODULE,xFreeLibrary,NULL> auto_module_handle;
  336. typedef auto_generic_handle<HANDLE,xCloseHandle,INVALID_HANDLE_VALUE> auto_file_handle;