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.

124 lines
4.1 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1999 - 1999
  6. //
  7. // File: ScriptHost.h
  8. //
  9. // Script Hosting implementation.
  10. //
  11. //--------------------------------------------------------------------------
  12. #ifndef SCRIPTHOST_H
  13. #define SCRIPTHOST_H
  14. #include "activscp.h"
  15. #include "tstring.h"
  16. #define SCRIPT_ENGINE_KEY _T("ScriptEngine")
  17. #define CLSIDSTR _T("CLSID")
  18. class CScriptHost;
  19. //+-------------------------------------------------------------------
  20. //
  21. // class: CScriptHostMgr
  22. //
  23. // Purpose: Manages all the script hosts (CScriptHost). Owned by
  24. // CAMCApp which calls ScExecuteScript.
  25. //
  26. // History: 11-05-1999 AnandhaG Created
  27. //
  28. //--------------------------------------------------------------------
  29. class CScriptHostMgr
  30. {
  31. public:
  32. CScriptHostMgr(LPDISPATCH pDispatch);
  33. ~CScriptHostMgr();
  34. public:
  35. // Accessors.
  36. SC ScGetMMCObject(LPUNKNOWN *ppunkItem);
  37. SC ScGetMMCTypeInfo(LPTYPEINFO *ppTypeInfo);
  38. // Members to run a script.
  39. SC ScExecuteScript(const tstring& strFileName);
  40. SC ScExecuteScript(LPOLESTR pszScriptText, const tstring& strExtn);
  41. private:
  42. SC ScLoadScriptFromFile (const tstring& strFileName, LPOLESTR* pszScriptText);
  43. SC ScDestroyScriptHosts();
  44. SC ScGetScriptEngine(const tstring& strFileName, tstring& strScriptEngine, CLSID& rClsidEngine);
  45. SC ScGetScriptEngineFromExtn(const tstring& strFileExtn, tstring& strScriptEngine, CLSID& rClsidEngine);
  46. SC ScExecuteScriptHelper(LPCOLESTR pszScriptText, const tstring strScriptEngine, const CLSID& EngineClsid);
  47. private:
  48. typedef std::map<tstring, tstring> ScriptExtnToScriptEngineNameMap;
  49. ScriptExtnToScriptEngineNameMap m_ScriptExtnToScriptEngineNameMap;
  50. typedef std::map<tstring, CLSID> ScriptExtnToScriptEngineMap;
  51. ScriptExtnToScriptEngineMap m_ScriptExtnToScriptEngineMap;
  52. typedef std::vector<IUnknownPtr> ArrayOfScriptHosts;
  53. ArrayOfScriptHosts m_ArrayOfHosts;
  54. IDispatchPtr m_spMMCObjectDispatch;
  55. ITypeInfoPtr m_spMMCObjectTypeInfo;
  56. };
  57. //+-------------------------------------------------------------------
  58. //
  59. // class: CScriptHost
  60. //
  61. // Purpose: Script Host (executes a single script).
  62. //
  63. // History: 11-05-1999 AnandhaG Created
  64. //
  65. //--------------------------------------------------------------------
  66. class CScriptHost : public CComObjectRoot,
  67. public IActiveScriptSite,
  68. public IActiveScriptSiteWindow
  69. {
  70. private:
  71. CScriptHost(const CScriptHost&);
  72. public:
  73. CScriptHost();
  74. ~CScriptHost();
  75. public:
  76. // ATL COM map
  77. BEGIN_COM_MAP(CScriptHost)
  78. COM_INTERFACE_ENTRY(IActiveScriptSite)
  79. COM_INTERFACE_ENTRY(IActiveScriptSiteWindow)
  80. END_COM_MAP()
  81. SC ScRunScript(CScriptHostMgr* pMgr, LPCOLESTR pszScriptText,
  82. const tstring& strScriptEngine, const CLSID& rEngineClsid);
  83. SC ScStopScript();
  84. // IActiveScriptSite methods.
  85. STDMETHOD(GetLCID) ( LCID *plcid);
  86. STDMETHOD(GetItemInfo) ( LPCOLESTR pstrName, DWORD dwReturnMask,
  87. IUnknown **ppunkItem, ITypeInfo **ppTypeInfo);
  88. STDMETHOD(GetDocVersionString)( BSTR *pbstrVersionString);
  89. STDMETHOD(OnScriptTerminate) ( const VARIANT *pvarResult, const EXCEPINFO *pexcepinfo);
  90. STDMETHOD(OnStateChange) (SCRIPTSTATE ssScriptState);
  91. STDMETHOD(OnScriptError) (IActiveScriptError *pase);
  92. STDMETHOD(OnEnterScript) (void);
  93. STDMETHOD(OnLeaveScript) (void);
  94. // IActiveScriptSiteWindow methods.
  95. STDMETHOD(GetWindow) (HWND *phwnd);
  96. STDMETHOD(EnableModeless) (BOOL fEnable);
  97. private:
  98. tstring m_strScriptEngine;
  99. CLSID m_EngineClsid;
  100. CScriptHostMgr* m_pScriptHostMgr;
  101. IActiveScriptPtr m_spActiveScriptEngine;
  102. IActiveScriptParsePtr m_spActiveScriptParser;
  103. };
  104. #endif SCRIPTHOST_H