{Unti AxScript V.1.0 05/28/97 - Converted Header File for Microsoft Activescript.
Original Conversion of The Activescript Header by David Zajac (dzajac@hiwaay.net) for delphi 2.x.
Modified by Brian Dupras (bdupras@dimensional.com) for delphi 3.0 Using InterfacesinsInstead of Classes (Which Was Necessary for D2).
This unit is released to the public No warrenty or guarentee of * anything * is expressed or implied Use this code at your own risk -.. Any damage is yourown fault for trusting me If you find any error in this code, fix it.. IFEOU'R Nice, Let Me Know About The Error So i can FIX IT, TOO.
This code has to date (May 28, 1997) only been tested for creating a host forActiveScript. I have not tried creating a scripting engine with it (and probablynever will). But I've been able to host both MS JScript and MS VBScript .
Good luck, Brian Dupras 5/28/97
-------------------------------------------------- --------------------------------
. Ahh..updates I've updated this unit slilghtly, and created a helper unit called (and aptly so) AXScriptHelp The only major additions were those to supportMS IE4 The other updates to this unit were minor -.. A few slight type differencesand Some parameter name change. Mostly Cosmetic stuff.
Again, Good Luck,
Brian 7/6/97
By The Way, JScript, VBScript and Activescript Are Registered TradeMarks OFMICROSoft Corporation.
-------------------------------------------------- ------------------------------ More Updates Still. Thank you Gary Warren King for Noticing That I'm an idiot.
The identifiers: SCRIPTTHREADID_CURRENT, SCRIPTTHREADID_BASE, andSCRIPTTHREADID_ALL were originally thought to be C MACROS Upon second look, however, they're not macros, they're #define constants that typcast the values-1, -2, and -3 to the #. Typdef scriptthreadid. Looking Into Another's Activescriptconversion Confirmed this, so The change.
Brian dupras 8/26/97
ps At the time of this writing, a slightly older demo using this header isavailable at the Delphi Super Page The URL ishttp:. //SunSITE.icm.edu.pl/delphi/, and the file is axscpd1.zip It can befound. Under Delphi 3, Apps with Sources. I Plan To Pust Axscpd2.zip Real Soonnow, So Get That One if it's there.}
Unit axscript;
Interface
Uses Windows, ActiveX;
Const // Category IDS Catid_Activescript: Tguid = '{F0B7A1A1-9847-11CF-8F20-00805F2CD064}'; CACID_ActivescriptParse: Tguid = '{F0B7A1A2-9847-11CF-8F20-00805F2CD064}';
// Interface IDs IID_IActiveScriptSite: TGUID = '{DB01A1E3-A42B-11cf-8F20-00805F2CD064}'; IID_IActiveScriptSiteWindow: TGUID = '{D10F6761-83E9-11cf-8F20-00805F2CD064}'; IID_IActiveScript: TGUID = '{BB1A2AE1-A4F9- 11cf-8F20-00805F2CD064} '; IID_IActiveScriptParse: TGUID =' {BB1A2AE2-A4F9-11cf-8F20-00805F2CD064} '; IID_IActiveScriptParseProcedure: TGUID =' {1CFF0050-6FDD-11d0-9328-00A0C90DCAA9} '; IID_IActiveScriptError: TGUID =' { EAE1BA61-A4ED-11CF-8F20-00805F2CD064} ';
// Constants used by ActiveX Scripting: SCRIPTITEM_ISVISIBLE = $ 00000002; SCRIPTITEM_ISSOURCE = $ 00000004; SCRIPTITEM_GLOBALMEMBERS = $ 00000008; SCRIPTITEM_ISPERSISTENT = $ 00000040; SCRIPTITEM_CODEONLY = $ 00000200; SCRIPTITEM_NOCODE = $ 00000400; SCRIPTITEM_ALL_FLAGS = (SCRIPTITEM_ISSOURCE or SCRIPTITEM_ISVISIBLE or SCRIPTITEM_ISPERSISTENT or SCRIPTITEM_GLOBALMEMBERS or SCRIPTITEM_NOCODE or SCRIPTITEM_CODEONLY); // Iactivescript :: addtypelib () Input Flags
ScriptTypelib_isControl = $ 00000010; ScriptTypelib_ispersistent = 00000040; ScriptTypelib_all_flags = (scripttypelib_iscontrol or scripttypelib_ispersistent);
// IactivescriptParse :: addscriptlet () And IactivescriptParse :: ParsescriptText () Input Flags * /
SCRIPTTEXT_DELAYEXECUTION = $ 00000001; SCRIPTTEXT_ISVISIBLE = $ 00000002; SCRIPTTEXT_ISEXPRESSION = $ 00000020; SCRIPTTEXT_ISPERSISTENT = $ 00000040; SCRIPTTEXT_HOSTMANAGESSOURCE = $ 00000080; SCRIPTTEXT_ALL_FLAGS = (SCRIPTTEXT_DELAYEXECUTION or SCRIPTTEXT_ISVISIBLE or SCRIPTTEXT_ISEXPRESSION or SCRIPTTEXT_HOSTMANAGESSOURCE or SCRIPTTEXT_ISPERSISTENT);
// IactivescriptParseprocedure :: ParseprocedureText () Input Flags
SCRIPTPROC_HOSTMANAGESSOURCE = $ 00000080; SCRIPTPROC_IMPLICIT_THIS = $ 00000100; SCRIPTPROC_IMPLICIT_PARENTS = $ 00000200; SCRIPTPROC_ALL_FLAGS = (SCRIPTPROC_HOSTMANAGESSOURCE or SCRIPTPROC_IMPLICIT_THIS or SCRIPTPROC_IMPLICIT_PARENTS); // IActiveScriptSite :: GetItemInfo () input flags * /
Scriptinfo_iunknown = $ 00000001; Scriptinfo_itypeInfo = $ 00000002; Scriptinfo_all_Flags = (scriptinfo_iunknown or scriptinfo_itypeinfo);
// Iactivescript :: Interrupt () Flags * /
ScriptInterrupt_Debug = 00000001; ScriptInterrupt_raiseException = $ 00000002; ScriptInterrupt_all_flags = (ScriptInterRupt_debug or scriptinterrupt_raiseexception);
TYPE // New IE4 TYPES TUSERHWND = HWnd; tuserbstr = Tbstr; tusexcepinfo = texcepinfo; tuservariant = olevariant;
// script state values TScriptState = (SCRIPTSTATE_UNINITIALIZED, SCRIPTSTATE_STARTED, SCRIPTSTATE_CONNECTED, SCRIPTSTATE_DISCONNECTED, SCRIPTSTATE_CLOSED, SCRIPTSTATE_INITIALIZED);
// script thread state value * / tscriptthreadstate = (scriptthreadstate_notinscript, scriptthreadstate_running);
// thread ids * / tscriptthreadid = DWORD;
const // Note: these SCRIPTTHREADID constants were originally macros // in the first version of this file See the note at the top // for more information (Thanks to Gary Warren King.) SCRIPTTHREADID_CURRENT = TScriptThreadId (-1); SCRIPTTHREADID_BASE.. = TscriptthreadID (-2); scriptthreadid_all = tscriptthreadid (-3);
type // Forward declarations IActiveScript = interface; IActiveScriptParse = interface; IActiveScriptParseProcedure = interface; IActiveScriptSite = interface; IActiveScriptSiteWindow = interface; IActiveScriptError = interface; IActiveScriptError = interface (IUnknown) [ '{EAE1BA61-A4ED-11CF-8F20-00805F2CD064}']
// HRESULT getExceptioninfo (// [out] excepinfo * pEXCEPINFO); Function getExceptioninfo (Out Excepinfo: Texcepinfo): hResult; stdcall;
// HRESULT GetSourcePosition (// [out] DWORD * pdwSourceCOntext, // [out] ULONG * pulLineNumber, // [out] LONG * plCharacterPosition); function GetSourcePosition (out SourceContext: DWORD; out LineNumber: ULONG; out CharacterPosition: LONGINT : HResult; stdcall;
// hResult getSourceLinetext (// [out] bstr * PBSTRSOURCELINE); Function getSource: lpwstr): hResult; stdcall; end; // Iactivescripterror Interface
IActiveScriptSite = Interface (IUnknown) [ '{DB01A1E3-A42B-11CF-8F20-00805F2CD064}'] // HRESULT GetLCID (// [out] LCID * plcid); // Allows the host application to indicate the local ID for localization / / of script / user interaction function getlcid (OUT LCID: TLCID): HRESULT; stdcall;
// HRESULT GETITEMINFO (// [in] lpcolestr pstrname, // [in] dword dwreturnmask, // [out] iUnknown ** PPIUnkitem, // [out] etypeinfo ** ppti); // caled by the script engine to look up named items in host application. // Used to map unresolved variable names in scripts to automation interface // in host application. The dwReturnMask parameter will indicate whether // the actual object (SCRIPTINFO_INKNOWN) or just a coclass type description // ( SCRIPTINFO_ITYPEINFO) is desired function GetItemInfo (const pstrName: POleStr; dwReturnMask:. DWORD; out ppiunkItem: IUnknown; out Info: ITypeInfo): HRESULT; stdcall; // HRESULT GetDocVersionString (// [out] BSTR * pbstrVersion); // Called by the script engine to get a text-based version number of the // current document. This string can be used to validate that any cached // state that the script engine may have saved is consistent with the // current document. function GetDocVers IONSTRING (OUT VERSION: TBSTR): HRESULT; stdcall;
// HRESULT OnScriptTerminate (// [in] const VARIANT * pvarResult, // [in] const EXCEPINFO * pexcepinfo);. // Called by the script engine when the script terminates In most cases // this method is not called, as IT IS Possible That The Parsed Script May // Be Used to Dispatch Events from The Host Application Function OnScriptterMinate (Const PvarResult: Olevariant; Const PEXCEPINFO: TEXCEPINFO): HRESULT; STDCALL
// HRESULT OnStateChange (// [in] SCRIPTSTATE ssScriptState); // Called by via the script engine when state changes either explicitly // SetScriptState or implicitly via other script engine events function OnStateChange (ScriptState: TScriptState):. HRESULT; stdcall; // HRESULT OnScriptError (// [in] IActiveScriptError * pscripterror); // Called when script execution or parsing encounters an error The script // engine will provide an implementation of IActiveScriptError that // describes the runtime error in terms of an EXCEPINFO. In addition to // indicating the location of the error in the Original Script text. Function OnScripTERROR: IACTISBRIPTERROR: HRESULT; stdcall;
// HRESULT Onenterscript (Void); // Called by the Script Engine to Indicate The Beginning of a Unit of Work. Function Onenterscript; stdcall;
// HRESULT ONLEVEScript (Void); // Called by The Script Engine to Indicate The Completion of a Unit of Work. Function Onleavescript: HRESULT; stdcall;
End; // Iactivescriptsite Interface
IActiveScriptSiteWindow = interface (IUnknown) [ '{D10F6761-83E9-11CF-8F20-00805F2CD064}'] // HRESULT GetWindow (// [out] HWND * phwnd); function GetWindow (out Handle: HWND): HRESULT; stdcall;
// hResult enablemodeless; Function EnableModeless: hResult; stdcall; end; // IactivescriptsItemWindow Interface
IActiveScript = interface (IUnknown) [ '{BB1A2AE1-A4F9-11CF-8F20-00805F2CD064}'] // HRESULT SetScriptSite (// [in] IActiveScriptSite * pass); // Conects the host's application site object to the engine function SetScriptSite ( ActiveScriptSite: IActiveScriptSite): HRESULT; stdcall; // HRESULT GetScriptSite (// [in] REFIID riid, // [iid_is] [out] void ** ppvObject); // Queries the engine for the connected site function GetScriptSite (riid: Tguid; OleObject: Pointer: HRESULT; stdcall;
// hResult setscriptState (// [in] scriptState ss); // causes the engine to enter the designate state function setscriptState (state: tscriptstate): hResult; stdcall;
// HRESULT getScriptState (// [out] scriptte * pss; // queries the engine for ITS Current State Function GetScriptState: HRESULT; stdcall;
// HRESULT Close (void); // forces the engine to enter the closed state, resetting any pased scripts // and disconnecting / release all of the host's objects. Function Close: HRESULT; stdcall;
// HRESULT AddNamedItem (// [in] LPCOLESTR pstrName, // [in] DWORD dwFlags);. // Adds a variable name to the namespace of the script engine The engine // will call the site's GetItemInfo to resolve the name to An Object. Function AddNamedItem (Name: Polestr; Flags: DWORD): HRESULT; stdcall;
// HRESULT ADDTYPELIB (// [in] refguid RguidTypelib, // [in] dword dwmajor, // [in] dword dwminor, // [in] dword dwflags); // address dwflags); // adds the Type and constant defintions Contained in the designated type // library to the namespace of the scripting engine function AddTypeLib (TypeLib: TGUID; Major: DWORD; Minor: DWORD; Flags: DWORD):. HRESULT; stdcall; // HRESULT GetScriptDispatch (// [in] LPCOLESTR pstrItemName, / / [Out] idispatch ** ppdisp); // gets the IDispatch pointer to the scripting engine. Function getscriptdispatch (item Disp: idispatch): hResult; stdcall;
// HRESULT GetCurrentScriptThreadID (// [out] SCRIPTTHREADID * pstidThread); // Gets the script's logical thread ID that corresponds to the current // physical thread This allows script engines to execute script code on // arbitrary threads that may be distinct. From the site's thread. function getcurrentscriptthreadid (Out Thread: Tscriptthread): hResult; stdcall;
// HRESULT GetScriptThreadID (// [in] DWORD dwWin32ThreadID, // [out] SCRIPTTHREADID * pstidThread); // Gets the logical thread ID that corresponds to the specified physical // thread This allows script engines to execute script code on arbitrary. // Threads That May Be distinct from the sites thread. Function GetScriptthreadId (Win32threadID: DWORD; OUT THREAD: TScriptthreadID): HRESULT; stdcall;
// HRESULT GetScriptThreadState (// [in] SCRIPTTHREADID stidThread, // [out] SCRIPTTHREADSTATE * pstsState); // Gets the logical thread ID running state, which is either // SCRIPTTHREADSTATE_NOTINSCRIPT or SCRIPTTHEADSTATE_RUNNING function GetScriptThreadState (Thread:. TScriptThreadID; out State: TScriptThreadState): HRESULT; stdcall; // HRESULT InterruptScriptThread (// [in] SCRIPTTHREADID stidThread, // [in] const EXCEPINFO * pexcepInfo, // [in] DWORD dwFlags); // Similar to Terminatethread, this method stope THE EXECUTION OF A Script Thread (Thread: TscriptthreadID; Const Excepinfo: Texcepinfo; Flags: DWORD): HRESULT; stdcall;
// HRESULT Clone (// [out] IActiveScript ** ppscript);. // Duplicates the current script engine, replicating any parsed script text // and named items, but no the actual pointers to the site's objects function Clone (out ActiveScript : Iactivescript: hResult; stdcall; end; // Iactivescript Interface
IactivescriptParse = Interface (IUNKNOWN) ['{BB1A2AE2-A4F9-11CF-8F20-00805F2CD064}']
// HRESULT INITNEW (VOID); Function Initnew: HRESULT; stdcall;
// HRESULT AddScriptlet (// [in] LPCOLESTR pstrDefaultName, // [in] LPCOLESTR pstrCode, // [in] LPCOLESTR pstrItemName, // [in] LPCOLESTR pstrSubItemName, // [in] LPCOLESTR pstrEventName, // [in] LPCOLESTR pstrDelimiter, // [in] DWORD dwSourceContextCookie, // [in] ULONG ulStartingLineNumber, // [in] DWORD dwFlags, // [out] BSTR * pbstrName, // [out] EXCEPINFO * pexcepinfo); function AddScriptlet (DefaultName : POleStr; Code: POleStr; ItemName: POleStr; SubItemName: POleStr; EventName: POleStr; Delimiter: POleStr; SourceContextCookie: DWORD; StartingLineNnumber: ULONG; Flags: DWORD; out Name: TBSTR; out ExcepInfo: TExcepInfo): HRESULT; stdcall; // HRESULT stdmethodcalltype ParsescriptText (// [in] lpcolestr pstrcode, // [in] lpcolestr pstritemname, // [in] iunknown * punkcontext, // [in] lp COLESTR pstrDelimiter, // [in] DWORD dwSourceContextCookie, // [in] ULONG ulStartingLineNumber, // [in] DWORD dwFlags, // [out] VARIANT * pvarResult, // [out] EXCEPINFO * pexcepinfo); function ParseScriptText (const pstrCode: POLESTR; const pstrItemName: POLESTR; const punkContext: IUnknown; const pstrDelimiter: POLESTR; dwSourceContextCookie: DWORD; ulStartingLineNumber: ULONG; dwFlags: DWORD; out pvarResult: OleVariant; out pExcepInfo: TExcepInfo): HRESULT; stdcall;
End; // IactivscriptParse Interface
IactivescriptParseprocedure = Interface (IUNKNOWN) ['{1cff0050-6fdd-11d0-9328-00a0c90dcaa9}']
function ParseProcedureText (const pstrCode: POLESTR; const pstrFormalParams: POLESTR; const pstrItemName: POLESTR; punkContext: IUnknown; const pstrDelimiter: POLESTR; dwSourceContextCookie: DWord; ulStartingLineNumber: ULong; dwFlags: DWord; out ppdisp: IDispatch): HResult; stdcall; end ; // IactivscriptParseprocedure Interface
IMPLEMENTATION
End.