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.

137 lines
3.1 KiB

  1. /*++
  2. Copyright (C) 1996-2001 Microsoft Corporation
  3. Module Name:
  4. COMMAIN.H
  5. Abstract:
  6. COM Helpers.
  7. History:
  8. --*/
  9. #ifndef __WBEM_COMMAIN__H_
  10. #define __WBEM_COMMAIN__H_
  11. #include <unk.h>
  12. #include <clsfac.h>
  13. HMODULE GetThisModuleHandle();
  14. class CComServer
  15. {
  16. public:
  17. virtual HRESULT Initialize() = 0;
  18. virtual void Uninitialize(){}
  19. virtual void PostUninitialize(){}
  20. virtual HRESULT InitializeCom();
  21. virtual void Register(){}
  22. virtual void Unregister(){}
  23. virtual BOOL CanShutdown(){ return TRUE; }
  24. CLifeControl* GetLifeControl();
  25. protected:
  26. CComServer();
  27. HRESULT AddClassInfo( REFCLSID rclsid,
  28. CUnkInternal* pFactory,
  29. LPTSTR szName,
  30. BOOL bFreeThreaded,
  31. BOOL bReallyFree = FALSE );
  32. // Assumes riid and ProxyStubClsId are same
  33. HRESULT RegisterInterfaceMarshaler(REFIID riid, LPTSTR szName,
  34. int nNumMembers, REFIID riidParent);
  35. // ProxyStubClsId must be explicitly specified
  36. HRESULT RegisterInterfaceMarshaler(REFIID riid, CLSID psclsid, LPTSTR szName,
  37. int nNumMembers, REFIID riidParent);
  38. HRESULT UnregisterInterfaceMarshaler(REFIID riid);
  39. };
  40. /***************************************************************************
  41. We are trying NOT to be dependant on wbemcomn in this module. This is
  42. so this library will not have to be paired with the static or dll version
  43. of wbemcomn. This is the reason for the following definitions ...
  44. ****************************************************************************/
  45. #ifndef STATUS_POSSIBLE_DEADLOCK
  46. #define STATUS_POSSIBLE_DEADLOCK (0xC0000194L)
  47. #endif /*STATUS_POSSIBLE_DEADLOCK */
  48. #ifndef InitializeCriticalSectionAndSpinCount
  49. WINBASEAPI
  50. BOOL
  51. WINAPI
  52. InitializeCriticalSectionAndSpinCount(
  53. IN OUT LPCRITICAL_SECTION lpCriticalSection,
  54. IN DWORD dwSpinCount
  55. );
  56. #endif
  57. DWORD MyBreakOnDbgAndRenterLoop(void);
  58. class CMyCritSec : public CRITICAL_SECTION
  59. {
  60. public:
  61. CMyCritSec()
  62. {
  63. bool initialized = (InitializeCriticalSectionAndSpinCount(this,0))?true:false;
  64. if (!initialized) throw CX_MemoryException();
  65. }
  66. ~CMyCritSec()
  67. {
  68. DeleteCriticalSection(this);
  69. }
  70. void Enter()
  71. {
  72. __try {
  73. EnterCriticalSection(this);
  74. } __except((STATUS_POSSIBLE_DEADLOCK == GetExceptionCode())? MyBreakOnDbgAndRenterLoop():EXCEPTION_CONTINUE_SEARCH) {
  75. }
  76. }
  77. void Leave()
  78. {
  79. LeaveCriticalSection(this);
  80. }
  81. };
  82. class CMyInCritSec
  83. {
  84. protected:
  85. CRITICAL_SECTION* m_pcs;
  86. public:
  87. CMyInCritSec(CRITICAL_SECTION* pcs) : m_pcs(pcs)
  88. {
  89. __try {
  90. EnterCriticalSection(m_pcs);
  91. } __except((STATUS_POSSIBLE_DEADLOCK == GetExceptionCode())? MyBreakOnDbgAndRenterLoop():EXCEPTION_CONTINUE_SEARCH) {
  92. }
  93. }
  94. inline ~CMyInCritSec()
  95. {
  96. LeaveCriticalSection(m_pcs);
  97. }
  98. };
  99. #endif