Source code of Windows XP (NT5)
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.

236 lines
7.3 KiB

  1. #ifndef SCRIPT_H
  2. #define SCRIPT_H
  3. /***************************************************************************
  4. Project: VB Script and JavaScript
  5. Reviewed:
  6. Copyright (c) Microsoft Corporation
  7. This defines the public interface to VB Script and JavaScript.
  8. ***************************************************************************/
  9. #include "activscp.h"
  10. typedef void *HSCRIPT; // Handle to a scripting environment instance
  11. typedef void *HENTRY; // Handle to a script entry point
  12. typedef unsigned long MODID;
  13. const MODID kmodGlobal = 0;
  14. // PFNOUTPUT is used for all output for the script, including compile errors,
  15. // printing (if ScriptAdmin is called to turn on printing), dumping pcode
  16. // (if requested when ScriptAddScript is called), etc.
  17. typedef void (_stdcall *PFNOUTPUT)(DWORD, LPCOLESTR, BOOL);
  18. enum SAdminEnum
  19. {
  20. scadEnableCreateObject = 1, // Only used in VER1
  21. scadEnablePrint,
  22. scadEnableTakeOutTrash, // Only used in JavaScript
  23. };
  24. STDAPI ScriptBreakThread(DWORD dwThreadID);
  25. inline void FreeExcepInfo(EXCEPINFO *pei)
  26. {
  27. if (pei->bstrSource)
  28. SysFreeString(pei->bstrSource);
  29. if (pei->bstrDescription)
  30. SysFreeString(pei->bstrDescription);
  31. if (pei->bstrHelpFile)
  32. SysFreeString(pei->bstrHelpFile);
  33. memset(pei, 0, sizeof(*pei));
  34. }
  35. struct ScriptException
  36. {
  37. IUnknown *punk;
  38. BSTR bstrUser; // user data as provided to AddToScript - binary data
  39. long ichMin; // character range of error
  40. long ichLim;
  41. long line; // line number of error (zero based)
  42. long ichMinLine; // starting char of the line
  43. BSTR bstrLine; // source line (if available)
  44. BOOL fReported; // been reported via IScriptSite->OnScriptError?
  45. // must be last
  46. EXCEPINFO ei;
  47. void Clear(void)
  48. { memset(this, 0, sizeof(*this)); }
  49. void Free(void)
  50. {
  51. FreeExcepInfo(&ei);
  52. if (NULL != punk)
  53. punk->Release();
  54. if (NULL != bstrUser)
  55. SysFreeString(bstrUser);
  56. if (NULL != bstrLine)
  57. SysFreeString(bstrLine);
  58. memset(this, 0, offsetof(ScriptException, ei));
  59. }
  60. };
  61. /***************************************************************************
  62. The COM Interfaces
  63. ***************************************************************************/
  64. enum
  65. {
  66. fdexNil = 0x00,
  67. fdexDontCreate = 0x01,
  68. fdexInitNull = 0x02,
  69. fdexCaseSensitive = 0x04,
  70. fdexLim = 0x80,
  71. };
  72. const DWORD kgrfdexAll = fdexLim - 1;
  73. // This is the interface for extensible IDispatch objects.
  74. class IDispatchEx : public IDispatch
  75. {
  76. public:
  77. // Get dispID for names, with options
  78. virtual HRESULT STDMETHODCALLTYPE GetIDsOfNamesEx(REFIID riid,
  79. LPOLESTR *prgpsz, UINT cpsz, LCID lcid, DISPID *prgid, DWORD grfdex) = 0;
  80. // Enumerate dispIDs and their associated "names".
  81. // Returns S_FALSE if the enumeration is done, S_OK if it's not, an
  82. // error code if the call fails.
  83. virtual HRESULT STDMETHODCALLTYPE GetNextDispID(DISPID id, DISPID *pid,
  84. BSTR *pbstrName) = 0;
  85. };
  86. // Interface on owner of an IScript object. To avoid circular refcounts,
  87. // the IScript implementation should not AddRef this interface.
  88. class IScriptSite : public IUnknown
  89. {
  90. public:
  91. // IScriptSite Methods
  92. // NOTE: OnEnterScript() and OnLeaveScript() will nest, but must be
  93. // balanced pairs.
  94. // OnEnterScript() is called before entering the execution loop.
  95. virtual void STDMETHODCALLTYPE OnEnterScript(void) = 0;
  96. // OnLeaveScript() is called upon exiting the execution loop.
  97. virtual void STDMETHODCALLTYPE OnLeaveScript(void) = 0;
  98. virtual HRESULT STDMETHODCALLTYPE GetActiveScriptSiteWindow(
  99. IActiveScriptSiteWindow **ppassw) = 0;
  100. // error feedback - the client should not muck with the sei. We own it.
  101. virtual HRESULT STDMETHODCALLTYPE OnScriptError(const ScriptException *psei) = 0;
  102. // LCID support
  103. virtual LCID STDMETHODCALLTYPE GetUserLcid(void) = 0;
  104. // call back to get an object for a name
  105. virtual HRESULT STDMETHODCALLTYPE GetExternObject(long lwCookie, IDispatch ** ppdisp) = 0;
  106. #if SCRIPT_DEBUGGER
  107. virtual HRESULT STDMETHODCALLTYPE DebugBreakPoint(IUnknown *punk,
  108. void *pvUser, long cbUser, long ichMin, long ichLim) = 0;
  109. #endif //SCRIPT_DEBUGGER
  110. #if VER2
  111. virtual DWORD STDMETHODCALLTYPE GetSafetyOptions(void) = 0;
  112. #endif //VER2
  113. virtual HRESULT STDMETHODCALLTYPE GetInterruptInfo(EXCEPINFO * pexcepinfo) = 0;
  114. };
  115. enum
  116. {
  117. fscrNil = 0x00,
  118. fscrDumpPcode = 0x01, // dump pcode to the output function
  119. fscrPersist = 0x08, // keep this code on reset
  120. fscrParseHTMLComments = 0x10,
  121. fscrReturnExpression = 0x20,// call should return the last expression
  122. fscrImpliedThis = 0x40, // 'this.' is optional (for Call)
  123. fscrDebug = 0x80, // keep this code around for debugging
  124. };
  125. #if SCRIPT_DEBUGGER
  126. enum BP_COMMAND
  127. {
  128. BPCMD_GET,
  129. BPCMD_SET,
  130. BPCMD_CLEAR,
  131. BPCMD_TOGGLE
  132. };
  133. #endif //SCRIPT_DEBUGGER
  134. class IScript : public IUnknown
  135. {
  136. public:
  137. // IScript methods
  138. virtual HRESULT STDMETHODCALLTYPE AddToScript(LPCOLESTR pszSrc, MODID mod,
  139. IUnknown *punk, void *pvData, long cbData, ULONG grfscr,
  140. HENTRY *phentryGlobal, ScriptException *pse) = 0;
  141. virtual HRESULT STDMETHODCALLTYPE AddObject(LPCOLESTR pszName,
  142. IDispatch *pdisp, MODID mod = kmodGlobal, long lwCookie = 0) = 0;
  143. virtual HRESULT STDMETHODCALLTYPE AddObjectMember(LPCOLESTR pszName,
  144. IDispatch *pdisp, DISPID dispID, MODID mod = kmodGlobal) = 0;
  145. virtual HRESULT STDMETHODCALLTYPE GetEntryPoint(LPCOLESTR pszName,
  146. HENTRY *phentry, MODID mod = kmodGlobal) = 0;
  147. virtual HRESULT STDMETHODCALLTYPE ReleaseEntryPoint(HENTRY hentry) = 0;
  148. virtual HRESULT STDMETHODCALLTYPE Call(HENTRY hentry, VARIANT *pvarRes,
  149. int cvarArgs, VARIANT *prgvarArgs, IDispatch *pdispThis = NULL,
  150. ScriptException *pse = NULL, DWORD grfscr = fscrNil) = 0;
  151. virtual HRESULT STDMETHODCALLTYPE Break(void) = 0;
  152. virtual HRESULT STDMETHODCALLTYPE Admin(SAdminEnum scad, void *pvArg = NULL,
  153. MODID mod = kmodGlobal) = 0;
  154. virtual void STDMETHODCALLTYPE SetOutputFunction(PFNOUTPUT pfn,
  155. DWORD dwOutput) = 0;
  156. virtual HRESULT STDMETHODCALLTYPE SetDefaultDispatch(MODID mod,
  157. IDispatch *pdisp) = 0;
  158. // psite may be NULL
  159. virtual void STDMETHODCALLTYPE SetScriptSite(IScriptSite *psite) = 0;
  160. #if WIN16
  161. virtual HRESULT STDMETHODCALLTYPE
  162. SetActiveScriptSitePoll(IActiveScriptSiteInterruptPoll *pPoll) = 0;
  163. #endif // WIN16
  164. virtual void STDMETHODCALLTYPE Enter(void) = 0;
  165. virtual void STDMETHODCALLTYPE Leave(void) = 0;
  166. // get an IDispatch wrapper for the module
  167. virtual HRESULT STDMETHODCALLTYPE GetDispatchForModule(MODID mod,
  168. IDispatch **ppdisp) = 0;
  169. // Reset/Clone functionality
  170. virtual HRESULT STDMETHODCALLTYPE Reset(void) = 0;
  171. virtual HRESULT STDMETHODCALLTYPE Clone(IScript **ppscript) = 0;
  172. virtual HRESULT STDMETHODCALLTYPE Execute(ScriptException *pse = NULL) = 0;
  173. #if SCRIPT_DEBUGGER
  174. virtual HRESULT STDMETHODCALLTYPE ToggleBreakPoint(IUnknown *punk, long ich,
  175. BP_COMMAND bpcmd, long *pichMin, long *pichLim, BOOL *pfSet) = 0;
  176. virtual HRESULT STDMETHODCALLTYPE SetOneTimeBreakOnEntry(BOOL fSet = TRUE) = 0;
  177. #endif //SCRIPT_DEBUGGER
  178. virtual HRESULT STDMETHODCALLTYPE GetLineNumber(IUnknown *punk, long ich,
  179. long *pline, long *pichMinLine, long *pichLimLine) = 0;
  180. virtual HRESULT STDMETHODCALLTYPE GetUserData(IUnknown *punk, BSTR *pbstr) = 0;
  181. #if SUPPORT_SCRIPT_HELPER
  182. #if DBG
  183. virtual HRESULT STDMETHODCALLTYPE DumpPCode(void) = 0;
  184. #endif // DBG
  185. #endif // SUPPORT_SCRIPT_HELPER
  186. };
  187. // helper to create a script object
  188. STDAPI CreateScript(IScript **ppscript, PFNOUTPUT pfn = NULL, DWORD dwOutput = 0);
  189. #endif // SCRIPT_H