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.

119 lines
4.0 KiB

  1. /***************************************************************************\
  2. *
  3. * File: ComManager.h
  4. *
  5. * Description:
  6. * ComManager.h defines the process-wide COM manager used for all COM, OLE
  7. * and Automation operations.
  8. *
  9. *
  10. * History:
  11. * 1/18/2000: JStall: Created
  12. *
  13. * Copyright (C) 2000 by Microsoft Corporation. All rights reserved.
  14. *
  15. \***************************************************************************/
  16. #if !defined(SERVICES__ComManager_h__INCLUDED)
  17. #define SERVICES__ComManager_h__INCLUDED
  18. #pragma once
  19. /***************************************************************************\
  20. *
  21. * class ComManager
  22. *
  23. * ComManager manages COM services including COM, OLE, and Automation. This
  24. * class is designed to be "per-thread", automatically shared data across
  25. * multiple threads.
  26. *
  27. * NOTE: This manager is delay-loads DLL's to manage performance and work on
  28. * down-level platforms.
  29. *
  30. \***************************************************************************/
  31. typedef HRESULT (WINAPI * CoInitializeExProc)(void * pvReserved, DWORD dwCoInit);
  32. typedef void (WINAPI * CoUninitializeProc)();
  33. typedef HRESULT (WINAPI * CoCreateInstanceProc)(REFCLSID rclsid, LPUNKNOWN punkOuter,
  34. DWORD dwClsContext, REFIID ridd, LPVOID * ppv);
  35. typedef HRESULT (WINAPI * OleInitializeProc)(LPVOID * pvReserved);
  36. typedef void (WINAPI * OleUninitializeProc)();
  37. typedef HRESULT (WINAPI * RegisterDragDropProc)(HWND hwnd, IDropTarget * pDropTarget);
  38. typedef HRESULT (WINAPI * RevokeDragDropProc)(HWND hwnd);
  39. typedef void (WINAPI * ReleaseStgMediumProc)(STGMEDIUM * pstg);
  40. typedef BSTR (WINAPI * SysAllocStringProc)(const OLECHAR * psz);
  41. typedef HRESULT (WINAPI * SysFreeStringProc)(BSTR bstr);
  42. typedef HRESULT (WINAPI * VariantInitProc)(VARIANTARG * pvarg);
  43. typedef HRESULT (WINAPI * VariantClearProc)(VARIANTARG * pvarg);
  44. class ComManager
  45. {
  46. // Construction
  47. public:
  48. ComManager();
  49. ~ComManager();
  50. // Operations
  51. public:
  52. enum EServices
  53. {
  54. sCOM = 0x00000001, // COM
  55. sAuto = 0x00000002, // OLE-Automation
  56. sOLE = 0x00000004, // OLE2
  57. };
  58. BOOL Init(UINT nMask);
  59. BOOL IsInit(UINT nMask) const;
  60. HRESULT CreateInstance(REFCLSID rclsid, IUnknown * punkOuter, REFIID riid, void ** ppv);
  61. BSTR SysAllocString(const OLECHAR * psz);
  62. HRESULT SysFreeString(BSTR bstr);
  63. HRESULT VariantInit(VARIANTARG * pvarg);
  64. HRESULT VariantClear(VARIANTARG * pvarg);
  65. HRESULT RegisterDragDrop(HWND hwnd, IDropTarget * pDropTarget);
  66. HRESULT RevokeDragDrop(HWND hwnd);
  67. void ReleaseStgMedium(STGMEDIUM * pstg);
  68. // Data
  69. protected:
  70. //
  71. // Shared data that is process wide- only need to load the DLL's once.
  72. //
  73. static int s_cRefs;
  74. static CritLock s_lock;
  75. static HINSTANCE s_hDllCOM; // Core "COM" / OLE
  76. static CoInitializeExProc s_pfnCoInit;
  77. static CoUninitializeProc s_pfnCoUninit;
  78. static CoCreateInstanceProc s_pfnCreate;
  79. static OleInitializeProc s_pfnOleInit;
  80. static OleUninitializeProc s_pfnOleUninit;
  81. static RegisterDragDropProc s_pfnRegisterDragDrop;
  82. static RevokeDragDropProc s_pfnRevokeDragDrop;
  83. static ReleaseStgMediumProc s_pfnReleaseStgMedium;
  84. static HINSTANCE s_hDllAuto; // OLE-automation
  85. static SysAllocStringProc s_pfnAllocString;
  86. static SysFreeStringProc s_pfnFreeString;
  87. static VariantInitProc s_pfnVariantInit;
  88. static VariantClearProc s_pfnVariantClear;
  89. //
  90. // Specific data that is "per-thread"- need to initialize COM / OLE on each
  91. // thread.
  92. //
  93. BOOL m_fInitCOM:1;
  94. BOOL m_fInitOLE:1;
  95. };
  96. #include "ComManager.inl"
  97. #endif // SERVICES__ComManager_h__INCLUDED