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.

143 lines
5.4 KiB

  1. /*****************************************************************************
  2. *
  3. * (C) COPYRIGHT MICROSOFT CORPORATION, 2000
  4. *
  5. * TITLE: tmplutil.h
  6. *
  7. * VERSION: 1.0
  8. *
  9. * AUTHOR: LazarI
  10. *
  11. * DATE: 10-Mar-2000
  12. *
  13. * DESCRIPTION: Placeholder for common utility templates & functions
  14. *
  15. *****************************************************************************/
  16. #ifndef _TMPLUTIL_H
  17. #define _TMPLUTIL_H
  18. ////////////////////////////////////////////////////////////////////////////////
  19. // **************************** INCLUDE ALL ****************************
  20. //
  21. #include "gensph.h" // generic smart pointers & handles
  22. #include "comutils.h" // COM utility classes & templates
  23. #include "w32utils.h" // Win32 utility classes & templates
  24. #include "cntutils.h" // Containers & Algorithms utility templates
  25. // max path limits
  26. #define SERVER_MAX_PATH (INTERNET_MAX_HOST_NAME_LENGTH + 1 + 2)
  27. #define PRINTER_MAX_PATH (SERVER_MAX_PATH + MAX_PATH + 1)
  28. #if defined(_DEBUG) && defined(_CRTDBG_MAP_ALLOC) // CRT mem debugging
  29. ////////////////////////////////////////////////////
  30. // CRT debug flags - infowise
  31. //
  32. // _CRTDBG_ALLOC_MEM_DF
  33. // _CRTDBG_DELAY_FREE_MEM_DF
  34. // _CRTDBG_CHECK_ALWAYS_DF
  35. // _CRTDBG_CHECK_CRT_DF
  36. // _CRTDBG_LEAK_CHECK_DF
  37. //
  38. #define CRT_DEBUG_SET_FLAG(a) _CrtSetDbgFlag( (a) | _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG))
  39. #define CRT_DEBUG_CLR_FLAG(a) _CrtSetDbgFlag(~(a) & _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG))
  40. // sends all reports to stdout
  41. #define CRT_DEBUG_REPORT_TO_STDOUT() \
  42. _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE); \
  43. _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDOUT); \
  44. _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE); \
  45. _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDOUT); \
  46. _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE); \
  47. _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDOUT) \
  48. // redefine new to be debug new
  49. #undef new
  50. #define new new(_NORMAL_BLOCK, __FILE__, __LINE__)
  51. #else
  52. #define CRT_DEBUG_SET_FLAG(a) ((void) 0)
  53. #define CRT_DEBUG_CLR_FLAG(a) ((void) 0)
  54. #define CRT_DEBUG_REPORT_TO_STDOUT() ((void) 0)
  55. #endif
  56. ////////////////////////////////////////////////
  57. // shell related services
  58. namespace ShellServices
  59. {
  60. // creates a PIDL to a printer in the local printers folder.
  61. // args:
  62. // [in] hwnd - window handle (in case we need to show UI - message box)
  63. // [in] pszPrinterName - full printer name.
  64. // [out] ppLocalPrnFolder - the printers folder (optional - may be NULL)
  65. // [out] ppidlPrinter - the PIDL of the printer pointed by pszPrinterName (optional - may be NULL)
  66. //
  67. // remarks:
  68. // pszPrinterName should be fully qualified printer name, i.e. if printer connection it should be
  69. // like "\\server\printer", if local printer just the printer name.
  70. //
  71. // returns:
  72. // S_OK on success, or OLE2 error otherwise
  73. HRESULT CreatePrinterPIDL(HWND hwnd, LPCTSTR pszPrinterName, IShellFolder **ppLocalPrnFolder, LPITEMIDLIST *ppidlPrinter);
  74. // loads a popup menu
  75. HMENU LoadPopupMenu(HINSTANCE hInstance, UINT id, UINT uSubOffset = 0);
  76. // initializes enum printer's autocomplete
  77. HRESULT InitPrintersAutoComplete(HWND hwndEdit);
  78. // helpers for the Enum* idioms
  79. enum { ENUM_MAX_RETRY = 5 };
  80. HRESULT EnumPrintersWrap(DWORD dwFlags, DWORD dwLevel, LPCTSTR pszName, BYTE **ppBuffer, DWORD *pcReturned);
  81. HRESULT GetJobWrap(HANDLE hPrinter, DWORD JobId, DWORD dwLevel, BYTE **ppBuffer, DWORD *pcReturned);
  82. // enumerates the shared resources on a server, for more info see SDK for NetShareEnum API.
  83. HRESULT NetAPI_EnumShares(LPCTSTR pszServer, DWORD dwLevel, BYTE **ppBuffer, DWORD *pcReturned);
  84. }
  85. // utility functions
  86. HRESULT LoadXMLDOMDoc(LPCTSTR pszURL, IXMLDOMDocument **ppXMLDoc);
  87. HRESULT CreateStreamFromURL(LPCTSTR pszURL, IStream **pps);
  88. HRESULT CreateStreamFromResource(LPCTSTR pszModule, LPCTSTR pszResType, LPCTSTR pszResName, IStream **pps);
  89. HRESULT GetCurrentThreadLastPopup(HWND *phwnd);
  90. HRESULT PrinterSplitFullName(LPCTSTR pszFullName, TCHAR szBuffer[], int nMaxLength, LPCTSTR *ppszServer,LPCTSTR *ppszPrinter);
  91. // generate proper HRESULT from Win32 last error
  92. inline HRESULT
  93. CreateHRFromWin32(DWORD dwError = GetLastError())
  94. {
  95. return (ERROR_SUCCESS == dwError) ? E_FAIL : HRESULT_FROM_WIN32(dwError);
  96. }
  97. inline HRESULT
  98. SafeGetModuleFileName(HMODULE hModule, LPTSTR lpBuffer, UINT nBufferLength)
  99. {
  100. DWORD cch = GetModuleFileName(hModule, lpBuffer, nBufferLength);
  101. //
  102. // Make sure the buffer is zero terminated.
  103. //
  104. lpBuffer[nBufferLength-1] = 0;
  105. //
  106. // Check if the buffer is large enough or we have truncation.
  107. //
  108. return (0 == cch) ? CreateHRFromWin32() :
  109. (cch >= nBufferLength) ? CreateHRFromWin32(ERROR_INSUFFICIENT_BUFFER) : S_OK;
  110. }
  111. LONG COMObjects_GetCount();
  112. #ifdef _GDIPLUS_H
  113. // gdiplus utility functions
  114. HRESULT Gdiplus2HRESULT(Gdiplus::Status status);
  115. HRESULT LoadAndScaleBmp(LPCTSTR pszURL, UINT nWidth, UINT nHeight, Gdiplus::Bitmap **ppBmp);
  116. HRESULT LoadAndScaleBmp(IStream *pStream, UINT nWidth, UINT nHeight, Gdiplus::Bitmap **ppBmp);
  117. #endif // endif _GDIPLUS_H
  118. // include the implementation of the template classes here
  119. #include "tmplutil.inl"
  120. #endif // endif _TMPLUTIL_H