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.

117 lines
3.7 KiB

  1. // CActCtx.h : Declaration of the CActCtx
  2. #ifndef __ACTCTX_H_
  3. #define __ACTCTX_H_
  4. #include "resource.h" // main symbols
  5. class CCS
  6. {
  7. public:
  8. CCS() { }
  9. ~CCS() { ::DeleteCriticalSection(&m_cs); }
  10. HRESULT Initialize() { __try { ::InitializeCriticalSection(&m_cs); } __except ((GetExceptionCode() == STATUS_NO_MEMORY) ? EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH) { return E_OUTOFMEMORY; } return NOERROR; }
  11. void Lock() { ::EnterCriticalSection(&m_cs); }
  12. void Unlock() { ::LeaveCriticalSection(&m_cs); }
  13. protected:
  14. CRITICAL_SECTION m_cs;
  15. };
  16. // forward declaration for friendship
  17. class CActivation;
  18. /////////////////////////////////////////////////////////////////////////////
  19. // CActCtx
  20. class ATL_NO_VTABLE CActCtx :
  21. public CComObjectRootEx<CComMultiThreadModel>,
  22. public CComCoClass<CActCtx, &CLSID_ActCtx>,
  23. public IDispatchImpl<IActCtx, &IID_IActCtx, &LIBID_ACTCTXLib>
  24. {
  25. friend CActivation;
  26. public:
  27. CActCtx()
  28. {
  29. m_pUnkMarshaler = NULL;
  30. m_hActCtx = NULL;
  31. }
  32. DECLARE_REGISTRY_RESOURCEID(IDR_ACTCTX)
  33. DECLARE_NOT_AGGREGATABLE(CActCtx)
  34. DECLARE_GET_CONTROLLING_UNKNOWN()
  35. DECLARE_PROTECT_FINAL_CONSTRUCT()
  36. BEGIN_COM_MAP(CActCtx)
  37. COM_INTERFACE_ENTRY(IActCtx)
  38. COM_INTERFACE_ENTRY(IDispatch)
  39. COM_INTERFACE_ENTRY_AGGREGATE(IID_IMarshal, m_pUnkMarshaler.p)
  40. END_COM_MAP()
  41. HRESULT FinalConstruct()
  42. {
  43. HRESULT hr = m_cs.Initialize();
  44. if (FAILED(hr))
  45. return hr;
  46. return ::CoCreateFreeThreadedMarshaler(
  47. GetControllingUnknown(), &m_pUnkMarshaler.p);
  48. }
  49. void FinalRelease()
  50. {
  51. m_pUnkMarshaler.Release();
  52. }
  53. CComPtr<IUnknown> m_pUnkMarshaler;
  54. // IActCtx
  55. public:
  56. STDMETHOD(GetObject)(VARIANT *pvarMoniker, VARIANT *pvarProgID, IDispatch **ppIDispatch);
  57. STDMETHOD(CreateObject)(BSTR ObjectReference, VARIANT *pvarLocation, IDispatch **ppIDispatch);
  58. STDMETHOD(get_Manifest)(/*[out, retval]*/ BSTR *pVal);
  59. STDMETHOD(put_Manifest)(/*[in]*/ BSTR newVal);
  60. STDMETHOD(get_ManifestText)(/*[out, retval]*/ BSTR *pVal);
  61. STDMETHOD(put_ManifestText)(/*[in]*/ BSTR bstrTextualManifest);
  62. STDMETHOD(get_ManifestURL)(/*[out, retval]*/ BSTR *pVal);
  63. STDMETHOD(put_ManifestURL)(/*[in]*/ BSTR bstrURL);
  64. protected:
  65. typedef enum {
  66. ACTCTX_MANIFEST_FILE=0,
  67. ACTCTX_MANIFEST_TEXT,
  68. ACTCTX_MANIFEST_URL
  69. }ACTCTX_MANIFEST_INFO_TYPE;
  70. HRESULT FetchManifestInfo(ACTCTX_MANIFEST_INFO_TYPE infotype, BSTR *pVal);
  71. HRESULT SetManifestInfo(ACTCTX_MANIFEST_INFO_TYPE infotype, BSTR newVal);
  72. HRESULT EnsureInitialized();
  73. static HANDLE WINAPI fakeCreateActCtxW(PCACTCTXW) { return NULL; }
  74. static VOID WINAPI fakeAddRefActCtx(HANDLE) { }
  75. static VOID WINAPI fakeReleaseActCtx(HANDLE) { }
  76. static BOOL WINAPI fakeActivateActCtx(HANDLE, ULONG_PTR *) { return TRUE; }
  77. static BOOL WINAPI fakeDeactivateActCtx(DWORD, ULONG_PTR) { return TRUE; }
  78. static HINSTANCE ms_hKERNEL32;
  79. typedef HANDLE (WINAPI *PFNCreateActCtxW)(PCACTCTXW);
  80. typedef VOID (WINAPI *PFNAddRefActCtx)(HANDLE);
  81. typedef VOID (WINAPI *PFNReleaseActCtx)(HANDLE);
  82. typedef BOOL (WINAPI *PFNActivateActCtx)(HANDLE, ULONG_PTR *);
  83. typedef BOOL (WINAPI *PFNDeactivateActCtx)(DWORD, ULONG_PTR);
  84. static PFNCreateActCtxW ms_pCreateActCtxW;
  85. static PFNAddRefActCtx ms_pAddRefActCtx;
  86. static PFNReleaseActCtx ms_pReleaseActCtx;
  87. static PFNActivateActCtx ms_pActivateActCtx;
  88. static PFNDeactivateActCtx ms_pDeactivateActCtx;
  89. CCS m_cs;
  90. CComBSTR m_bstrManifest;
  91. CComBSTR m_bstrManifestURL;
  92. CComBSTR m_bstrManifestText;
  93. HANDLE m_hActCtx;
  94. };
  95. #endif //__ACTCTX_H_