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.

197 lines
2.7 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. util.cpp
  5. Abstract:
  6. This module contains utility routines for the fax transport provider.
  7. Author:
  8. Wesley Witt (wesw) 13-Aug-1996
  9. --*/
  10. #include "faxext.h"
  11. //
  12. // globals
  13. //
  14. BOOL oleInitialized;
  15. LPSTR Platforms[] =
  16. {
  17. "Windows NT x86",
  18. "Windows NT R4000",
  19. "Windows NT Alpha_AXP",
  20. "Windows NT PowerPC"
  21. };
  22. LPVOID
  23. MapiMemAlloc(
  24. DWORD Size
  25. )
  26. /*++
  27. Routine Description:
  28. Memory allocator.
  29. Arguments:
  30. Size - Number of bytes to allocate.
  31. Return Value:
  32. Pointer to the allocated memory or NULL for failure.
  33. --*/
  34. {
  35. LPVOID ptr;
  36. HRESULT hResult;
  37. hResult = MAPIAllocateBuffer( Size, &ptr );
  38. if (hResult) {
  39. ptr = NULL;
  40. } else {
  41. ZeroMemory( ptr, Size );
  42. }
  43. return ptr;
  44. }
  45. VOID
  46. MapiMemFree(
  47. LPVOID ptr
  48. )
  49. /*++
  50. Routine Description:
  51. Memory de-allocator.
  52. Arguments:
  53. ptr - Pointer to the memory block.
  54. Return Value:
  55. None.
  56. --*/
  57. {
  58. if (ptr) {
  59. MAPIFreeBuffer( ptr );
  60. }
  61. }
  62. PVOID
  63. MyGetPrinter(
  64. LPSTR PrinterName,
  65. DWORD level
  66. )
  67. /*++
  68. Routine Description:
  69. Wrapper function for GetPrinter spooler API
  70. Arguments:
  71. hPrinter - Identifies the printer in question
  72. level - Specifies the level of PRINTER_INFO_x structure requested
  73. Return Value:
  74. Pointer to a PRINTER_INFO_x structure, NULL if there is an error
  75. --*/
  76. {
  77. HANDLE hPrinter;
  78. PBYTE pPrinterInfo = NULL;
  79. DWORD cbNeeded;
  80. PRINTER_DEFAULTS PrinterDefaults;
  81. PrinterDefaults.pDatatype = NULL;
  82. PrinterDefaults.pDevMode = NULL;
  83. PrinterDefaults.DesiredAccess = PRINTER_READ; //PRINTER_ALL_ACCESS;
  84. if (!OpenPrinter( PrinterName, &hPrinter, &PrinterDefaults )) {
  85. return NULL;
  86. }
  87. if (!GetPrinter( hPrinter, level, NULL, 0, &cbNeeded ) &&
  88. GetLastError() == ERROR_INSUFFICIENT_BUFFER &&
  89. (pPrinterInfo = (PBYTE) MemAlloc( cbNeeded )) &&
  90. GetPrinter( hPrinter, level, pPrinterInfo, cbNeeded, &cbNeeded ))
  91. {
  92. ClosePrinter( hPrinter );
  93. return pPrinterInfo;
  94. }
  95. ClosePrinter( hPrinter );
  96. MemFree( pPrinterInfo );
  97. return NULL;
  98. }
  99. LPSTR
  100. RemoveLastNode(
  101. LPTSTR Path
  102. )
  103. /*++
  104. Routine Description:
  105. Removes the last node from a path string.
  106. Arguments:
  107. Path - Path string.
  108. Return Value:
  109. Pointer to the path string.
  110. --*/
  111. {
  112. DWORD i;
  113. if (Path == NULL || Path[0] == 0) {
  114. return Path;
  115. }
  116. i = strlen(Path)-1;
  117. if (Path[i] == '\\') {
  118. Path[i] = 0;
  119. i -= 1;
  120. }
  121. for (; i>0; i--) {
  122. if (Path[i] == '\\') {
  123. Path[i+1] = 0;
  124. break;
  125. }
  126. }
  127. return Path;
  128. }