Source code of Windows XP (NT5)
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.

657 lines
11 KiB

  1. /*++
  2. Copyright (c) 1995 Microsoft Corporation
  3. Module Name:
  4. debug.h
  5. Abstract:
  6. This file defines the debugging interfaces
  7. available to the FAX compoments.
  8. Author:
  9. Wesley Witt (wesw) 22-Dec-1995
  10. Environment:
  11. User Mode
  12. --*/
  13. #ifndef _FAXUTIL_
  14. #define _FAXUTIL_
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18. #define OffsetToString( Offset, Buffer ) ((Offset) ? (LPTSTR) ((Buffer) + ((ULONG_PTR) Offset)) : NULL)
  19. #define StringSize(_s) (( _s ) ? (_tcslen( _s ) + 1) * sizeof(TCHAR) : 0)
  20. #define MAX_GUID_STRING_LEN 39 // 38 chars + terminator null
  21. #define FAXBITS 1728
  22. #define FAXBYTES (FAXBITS/BYTEBITS)
  23. #define MAXHORZBITS FAXBITS
  24. #define MAXVERTBITS 3000 // 14inches plus
  25. #define MINUTES_PER_HOUR 60
  26. #define MINUTES_PER_DAY (24 * 60)
  27. #define SECONDS_PER_MINUTE 60
  28. #define SECONDS_PER_HOUR (SECONDS_PER_MINUTE * MINUTES_PER_HOUR)
  29. #define SECONDS_PER_DAY (MINUTES_PER_DAY * SECONDS_PER_MINUTE)
  30. #define FILETIMETICKS_PER_SECOND 10000000 // 100 nanoseconds / second
  31. #define FILETIMETICKS_PER_DAY ((LONGLONG) FILETIMETICKS_PER_SECOND * (LONGLONG) SECONDS_PER_DAY)
  32. #define MILLISECONDS_PER_SECOND 1000
  33. #ifndef MAKELONGLONG
  34. #define MAKELONGLONG(low,high) ((LONGLONG)(((DWORD)(low)) | ((LONGLONG)((DWORD)(high))) << 32))
  35. #endif
  36. #define HideWindow(_hwnd) SetWindowLong((_hwnd),GWL_STYLE,GetWindowLong((_hwnd),GWL_STYLE)&~WS_VISIBLE)
  37. #define UnHideWindow(_hwnd) SetWindowLong((_hwnd),GWL_STYLE,GetWindowLong((_hwnd),GWL_STYLE)|WS_VISIBLE)
  38. #define DWord2FaxTime(pFaxTime, dwValue) (pFaxTime)->hour = LOWORD(dwValue), (pFaxTime)->minute = HIWORD(dwValue)
  39. #define FaxTime2DWord(pFaxTime) MAKELONG((pFaxTime)->hour, (pFaxTime)->minute)
  40. #define EMPTY_STRING L""
  41. #define IsSmallBiz() (ValidateProductSuite( VER_SUITE_SMALLBUSINESS | VER_SUITE_SMALLBUSINESS_RESTRICTED))
  42. #define IsCommServer() (ValidateProductSuite( VER_SUITE_COMMUNICATIONS ))
  43. #define IsProductSuite() (ValidateProductSuite( VER_SUITE_SMALLBUSINESS | VER_SUITE_SMALLBUSINESS_RESTRICTED | VER_SUITE_COMMUNICATIONS ))
  44. typedef GUID *PGUID;
  45. //
  46. // debugging information
  47. //
  48. #ifndef FAXUTIL_DEBUG
  49. #if DBG
  50. #define Assert(exp) if(!(exp)) {AssertError(TEXT(#exp),TEXT(__FILE__),__LINE__);}
  51. #define DebugPrint(_x_) dprintf _x_
  52. #define DebugStop(_x_) {\
  53. dprintf _x_;\
  54. dprintf(TEXT("Stopping at %s @ %d"),TEXT(__FILE__),__LINE__);\
  55. __try {\
  56. DebugBreak();\
  57. } __except (UnhandledExceptionFilter(GetExceptionInformation())) {\
  58. }\
  59. }
  60. #else
  61. #define Assert(exp)
  62. #define DebugPrint(_x_)
  63. #define DebugStop(_x_)
  64. #endif
  65. extern BOOL ConsoleDebugOutput;
  66. void
  67. dprintf(
  68. LPCTSTR Format,
  69. ...
  70. );
  71. VOID
  72. AssertError(
  73. LPCTSTR Expression,
  74. LPCTSTR File,
  75. ULONG LineNumber
  76. );
  77. #endif
  78. //
  79. // list management
  80. //
  81. #ifndef NO_FAX_LIST
  82. #define InitializeListHead(ListHead) {\
  83. (ListHead)->Flink = (ListHead)->Blink = (ListHead);\
  84. Assert((ListHead)->Flink && (ListHead)->Blink);\
  85. }
  86. #define IsListEmpty(ListHead) \
  87. ((ListHead)->Flink == (ListHead))
  88. #define InsertHeadList(ListHead,Entry) {\
  89. PLIST_ENTRY _EX_Flink;\
  90. PLIST_ENTRY _EX_ListHead;\
  91. _EX_ListHead = (ListHead);\
  92. _EX_Flink = _EX_ListHead->Flink;\
  93. (Entry)->Flink = _EX_Flink;\
  94. (Entry)->Blink = _EX_ListHead;\
  95. _EX_Flink->Blink = (Entry);\
  96. _EX_ListHead->Flink = (Entry);\
  97. Assert((ListHead)->Flink && (ListHead)->Blink && (Entry)->Blink && (Entry)->Flink);\
  98. }
  99. #define InsertTailList(ListHead,Entry) {\
  100. PLIST_ENTRY _EX_Blink;\
  101. PLIST_ENTRY _EX_ListHead;\
  102. _EX_ListHead = (ListHead);\
  103. _EX_Blink = _EX_ListHead->Blink;\
  104. (Entry)->Flink = _EX_ListHead;\
  105. (Entry)->Blink = _EX_Blink;\
  106. _EX_Blink->Flink = (Entry);\
  107. _EX_ListHead->Blink = (Entry);\
  108. Assert((ListHead)->Flink && (ListHead)->Blink && (Entry)->Blink && (Entry)->Flink);\
  109. }
  110. #define RemoveEntryList(Entry) {\
  111. PLIST_ENTRY _EX_Blink;\
  112. PLIST_ENTRY _EX_Flink;\
  113. Assert((Entry)->Blink && (Entry)->Flink);\
  114. _EX_Flink = (Entry)->Flink;\
  115. _EX_Blink = (Entry)->Blink;\
  116. _EX_Blink->Flink = _EX_Flink;\
  117. _EX_Flink->Blink = _EX_Blink;\
  118. }
  119. #define RemoveHeadList(ListHead) \
  120. Assert((ListHead)->Flink);\
  121. (ListHead)->Flink;\
  122. {RemoveEntryList((ListHead)->Flink)}
  123. #endif
  124. //
  125. // memory allocation
  126. //
  127. #ifndef FAXUTIL_MEM
  128. #define HEAP_SIZE (1024*1024)
  129. #ifdef FAX_HEAP_DEBUG
  130. #define HEAP_SIG 0x69696969
  131. typedef struct _HEAP_BLOCK {
  132. LIST_ENTRY ListEntry;
  133. ULONG Signature;
  134. ULONG Size;
  135. ULONG Line;
  136. #ifdef UNICODE
  137. WCHAR File[22];
  138. #else
  139. CHAR File[20];
  140. #endif
  141. } HEAP_BLOCK, *PHEAP_BLOCK;
  142. #define MemAlloc(s) pMemAlloc(s,__LINE__,__FILE__)
  143. #define MemReAlloc(d,s) pMemReAlloc(d,s,__LINE__,__FILE__)
  144. #define MemFree(p) pMemFree(p,__LINE__,__FILE__)
  145. #define MemFreeForHeap(h,p) pMemFreeForHeap(h,p,__LINE__,__FILE__)
  146. #define CheckHeap(p) pCheckHeap(p,__LINE__,__FILE__)
  147. #else
  148. #define MemAlloc(s) pMemAlloc(s)
  149. #define MemReAlloc(d,s) pMemReAlloc(d,s)
  150. #define MemFree(p) pMemFree(p)
  151. #define MemFreeForHeap(h,p) pMemFreeForHeap(h,p)
  152. #define CheckHeap(p)
  153. #endif
  154. typedef LPVOID (WINAPI *PMEMALLOC) (DWORD);
  155. typedef LPVOID (WINAPI *PMEMREALLOC) (LPVOID,DWORD);
  156. typedef VOID (WINAPI *PMEMFREE) (LPVOID);
  157. #define HEAPINIT_NO_VALIDATION 0x00000001
  158. #define HEAPINIT_NO_STRINGS 0x00000002
  159. HANDLE
  160. HeapInitialize(
  161. HANDLE hHeap,
  162. PMEMALLOC pMemAlloc,
  163. PMEMFREE pMemFree,
  164. DWORD Flags
  165. );
  166. BOOL
  167. HeapExistingInitialize(
  168. HANDLE hExistHeap
  169. );
  170. BOOL
  171. HeapCleanup(
  172. VOID
  173. );
  174. #ifdef FAX_HEAP_DEBUG
  175. VOID
  176. pCheckHeap(
  177. PVOID MemPtr,
  178. ULONG Line,
  179. LPSTR File
  180. );
  181. VOID
  182. PrintAllocations(
  183. VOID
  184. );
  185. #else
  186. #define PrintAllocations()
  187. #endif
  188. PVOID
  189. pMemAlloc(
  190. ULONG AllocSize
  191. #ifdef FAX_HEAP_DEBUG
  192. ,ULONG Line
  193. ,LPSTR File
  194. #endif
  195. );
  196. PVOID
  197. pMemReAlloc(
  198. PVOID dest,
  199. ULONG AllocSize
  200. #ifdef FAX_HEAP_DEBUG
  201. ,ULONG Line
  202. ,LPSTR File
  203. #endif
  204. );
  205. VOID
  206. pMemFree(
  207. PVOID MemPtr
  208. #ifdef FAX_HEAP_DEBUG
  209. ,ULONG Line
  210. ,LPSTR File
  211. #endif
  212. );
  213. VOID
  214. pMemFreeForHeap(
  215. HANDLE hHeap,
  216. PVOID MemPtr
  217. #ifdef FAX_HEAP_DEBUG
  218. ,ULONG Line
  219. ,LPSTR File
  220. #endif
  221. );
  222. #endif
  223. //
  224. // file functions
  225. //
  226. #ifndef FAXUTIL_FILE
  227. typedef struct _FILE_MAPPING {
  228. HANDLE hFile;
  229. HANDLE hMap;
  230. LPBYTE fPtr;
  231. DWORD fSize;
  232. } FILE_MAPPING, *PFILE_MAPPING;
  233. BOOL
  234. MapFileOpen(
  235. LPTSTR FileName,
  236. BOOL ReadOnly,
  237. DWORD ExtendBytes,
  238. PFILE_MAPPING FileMapping
  239. );
  240. VOID
  241. MapFileClose(
  242. PFILE_MAPPING FileMapping,
  243. DWORD TrimOffset
  244. );
  245. #endif
  246. //
  247. // printer functions
  248. //
  249. PVOID
  250. MyEnumPrinters(
  251. LPTSTR pServerName,
  252. DWORD level,
  253. PDWORD pcPrinters,
  254. DWORD dwFlags
  255. );
  256. //
  257. // string functions
  258. //
  259. #ifndef FAXUTIL_STRING
  260. LPTSTR
  261. StringDup(
  262. LPCTSTR String
  263. );
  264. LPWSTR
  265. AnsiStringToUnicodeString(
  266. LPCSTR AnsiString
  267. );
  268. LPSTR
  269. UnicodeStringToAnsiString(
  270. LPCWSTR UnicodeString
  271. );
  272. VOID
  273. FreeString(
  274. LPVOID String
  275. );
  276. VOID
  277. MakeDirectory(
  278. LPCTSTR Dir
  279. );
  280. VOID
  281. DeleteDirectory(
  282. LPTSTR Dir
  283. );
  284. VOID
  285. HideDirectory(
  286. LPTSTR Dir
  287. );
  288. LPTSTR
  289. ConcatenatePaths(
  290. LPTSTR Path,
  291. LPCTSTR Append
  292. );
  293. int
  294. MyLoadString(
  295. HINSTANCE hInstance,
  296. UINT uID,
  297. LPTSTR lpBuffer,
  298. int nBufferMax,
  299. LANGID LangID
  300. );
  301. VOID
  302. ConsoleDebugPrint(
  303. LPCTSTR buf
  304. );
  305. int
  306. FormatElapsedTimeStr(
  307. FILETIME *ElapsedTime,
  308. LPTSTR TimeStr,
  309. DWORD StringSize
  310. );
  311. LPTSTR
  312. ExpandEnvironmentString(
  313. LPCTSTR EnvString
  314. );
  315. LPTSTR
  316. GetEnvVariable(
  317. LPCTSTR EnvString
  318. );
  319. #endif
  320. //
  321. // product suite functions
  322. //
  323. #ifndef FAXUTIL_SUITE
  324. BOOL
  325. ValidateProductSuite(
  326. WORD Mask
  327. );
  328. DWORD
  329. GetProductType(
  330. VOID
  331. );
  332. #endif
  333. //
  334. // registry functions
  335. //
  336. #ifndef FAXUTIL_REG
  337. typedef BOOL (WINAPI *PREGENUMCALLBACK) (HKEY,LPTSTR,DWORD,LPVOID);
  338. HKEY
  339. OpenRegistryKey(
  340. HKEY hKey,
  341. LPCTSTR KeyName,
  342. BOOL CreateNewKey,
  343. REGSAM SamDesired
  344. );
  345. //
  346. // caution!!! this is a recursive delete function !!!
  347. //
  348. BOOL
  349. DeleteRegistryKey(
  350. HKEY hKey,
  351. LPCTSTR SubKey
  352. );
  353. DWORD
  354. EnumerateRegistryKeys(
  355. HKEY hKey,
  356. LPCTSTR KeyName,
  357. BOOL ChangeValues,
  358. PREGENUMCALLBACK EnumCallback,
  359. LPVOID ContextData
  360. );
  361. LPTSTR
  362. GetRegistryString(
  363. HKEY hKey,
  364. LPCTSTR ValueName,
  365. LPCTSTR DefaultValue
  366. );
  367. LPTSTR
  368. GetRegistryStringExpand(
  369. HKEY hKey,
  370. LPCTSTR ValueName,
  371. LPCTSTR DefaultValue
  372. );
  373. LPTSTR
  374. GetRegistryStringMultiSz(
  375. HKEY hKey,
  376. LPCTSTR ValueName,
  377. LPCTSTR DefaultValue,
  378. LPDWORD StringSize
  379. );
  380. DWORD
  381. GetRegistryDword(
  382. HKEY hKey,
  383. LPCTSTR ValueName
  384. );
  385. LPBYTE
  386. GetRegistryBinary(
  387. HKEY hKey,
  388. LPCTSTR ValueName,
  389. LPDWORD DataSize
  390. );
  391. DWORD
  392. GetSubKeyCount(
  393. HKEY hKey
  394. );
  395. DWORD
  396. GetMaxSubKeyLen(
  397. HKEY hKey
  398. );
  399. BOOL
  400. SetRegistryStringExpand(
  401. HKEY hKey,
  402. LPCTSTR ValueName,
  403. LPCTSTR Value
  404. );
  405. BOOL
  406. SetRegistryString(
  407. HKEY hKey,
  408. LPCTSTR ValueName,
  409. LPCTSTR Value
  410. );
  411. BOOL
  412. SetRegistryDword(
  413. HKEY hKey,
  414. LPCTSTR ValueName,
  415. DWORD Value
  416. );
  417. BOOL
  418. SetRegistryBinary(
  419. HKEY hKey,
  420. LPCTSTR ValueName,
  421. const LPBYTE Value,
  422. LONG Length
  423. );
  424. BOOL
  425. SetRegistryStringMultiSz(
  426. HKEY hKey,
  427. LPCTSTR ValueName,
  428. LPCTSTR Value,
  429. DWORD Length
  430. );
  431. #endif
  432. //
  433. // shortcut routines
  434. //
  435. #ifndef FAXUTIL_SHORTCUT
  436. BOOL
  437. ResolveShortcut(
  438. LPTSTR pLinkName,
  439. LPTSTR pFileName
  440. );
  441. BOOL
  442. CreateShortcut(
  443. LPTSTR pLinkName,
  444. LPTSTR pFileName
  445. );
  446. BOOL
  447. IsCoverPageShortcut(
  448. LPCTSTR pLinkName
  449. );
  450. BOOL
  451. GetServerCpDir(
  452. LPCTSTR ServerName OPTIONAL,
  453. LPTSTR CpDir,
  454. DWORD CpDirSize
  455. );
  456. BOOL
  457. GetClientCpDir(
  458. LPTSTR CpDir,
  459. DWORD CpDirSize
  460. );
  461. BOOL
  462. GetSpecialPath(
  463. int Id,
  464. LPTSTR DirBuffer
  465. );
  466. #endif
  467. //
  468. // fax adaptive answer modem routines
  469. //
  470. #ifndef FAXUTIL_ADAPTIVE
  471. #include <setupapi.h>
  472. LPVOID
  473. InitializeAdaptiveAnswerList(
  474. HINF hInf
  475. );
  476. BOOL
  477. IsModemAdaptiveAnswer(
  478. LPVOID ModemList,
  479. LPCTSTR ModemId
  480. );
  481. #endif
  482. //
  483. // The following macros are used to establish the semantics needed
  484. // to do a return from within a try-finally clause. As a rule every
  485. // try clause must end with a label call try_exit. For example,
  486. //
  487. // try {
  488. // :
  489. // :
  490. //
  491. // try_exit: NOTHING;
  492. // } finally {
  493. //
  494. // :
  495. // :
  496. // }
  497. //
  498. // Every return statement executed inside of a try clause should use the
  499. // try_return macro. If the compiler fully supports the try-finally construct
  500. // then the macro should be
  501. //
  502. // #define try_return(S) { return(S); }
  503. //
  504. // If the compiler does not support the try-finally construct then the macro
  505. // should be
  506. //
  507. // #define try_return(S) { S; goto try_exit; }
  508. //
  509. // This was borrowed from fatprocs.h
  510. #ifdef DBG
  511. #define try_fail(S) { DebugPrint(( TEXT("Failure in FILE %s LINE %d"), TEXT(__FILE__), __LINE__ )); S; goto try_exit; }
  512. #else
  513. #define try_fail(S) { S; goto try_exit; }
  514. #endif
  515. #define try_return(S) { S; goto try_exit; }
  516. #define NOTHING
  517. #ifdef __cplusplus
  518. }
  519. #endif
  520. #endif