The Labs \ Source Viewer \ SSCLI \ System.Net.ComImports \ IOleServiceProvider

  1. //------------------------------------------------------------------------------
  2. // <copyright file="_ComImports.cs" company="Microsoft">
  3. //
  4. // Copyright (c) 2006 Microsoft Corporation. All rights reserved.
  5. //
  6. // The use and distribution terms for this software are contained in the file
  7. // named license.txt, which can be found in the root of this distribution.
  8. // By using this software in any fashion, you are agreeing to be bound by the
  9. // terms of this license.
  10. //
  11. // You must not remove this notice, or any other, from this software.
  12. //
  13. // </copyright>
  14. //------------------------------------------------------------------------------
  15. #define AUTOPROXY_MANAGED_JSCRIPT
  16. #if !AUTOPROXY_MANAGED_JSCRIPT
  17. namespace System.Net.ComImports
  18. {
  19.     using System.Runtime.InteropServices;
  20.     using EXCEPINFO = System.Runtime.InteropServices.ComTypes.EXCEPINFO;
  21.    
  22.     //
  23.     // HRESULTs
  24.     //
  25.    
  26.     internal enum HRESULT
  27.     {
  28.         TYPE_E_ELEMENTNOTFOUND = unchecked((int)2147647531u),
  29.         SCRIPT_E_REPORTED = unchecked((int)2147614977u),
  30.         E_NOTIMPL = unchecked((int)2147500033u),
  31.         E_NOINTERFACE = unchecked((int)2147500034u),
  32.         S_OK = 0,
  33.         S_FALSE = 1
  34.     }
  35.    
  36.    
  37.     //
  38.     // Scripting Interfaces
  39.     //
  40.    
  41.     internal enum ScriptState : uint
  42.     {
  43.         Uninitialized = 0,
  44.         Started = 1,
  45.         Connected = 2,
  46.         Disconnected = 3,
  47.         Closed = 4,
  48.         Initialized = 5
  49.     }
  50.    
  51.     internal enum ScriptThreadState : uint
  52.     {
  53.         NotInScript = 0,
  54.         Running = 1
  55.     }
  56.    
  57.     [Flags()]
  58.     internal enum ScriptText : uint
  59.     {
  60.         None = 0,
  61.        
  62.         DelayExecution = 1,
  63.         IsVisible = 2,
  64.         IsExpression = 32,
  65.         IsPersistent = 64,
  66.         HostManageSource = 128
  67.     }
  68.    
  69.     [Flags()]
  70.     internal enum ScriptItem : uint
  71.     {
  72.         None = 0,
  73.        
  74.         IsVisible = 2,
  75.         IsSource = 4,
  76.         GlobalMembers = 8,
  77.         IsPersistent = 64,
  78.         CodeOnly = 512,
  79.         NoCode = 1024
  80.     }
  81.    
  82.     [Flags()]
  83.     internal enum ScriptInfo : uint
  84.     {
  85.         None = 0,
  86.        
  87.         IUnknown = 1,
  88.         ITypeInfo = 2
  89.     }
  90.    
  91.     //
  92.     // A "fake" interface to use to interact with the script itself through IDispatch.
  93.     // It uses the IDispatch guid. New methods can be added as needed in any order.
  94.     //
  95.     [ComImport()]
  96.     [Guid("00020400-0000-0000-C000-000000000046")]
  97.     [InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
  98.     internal interface IScript
  99.     {
  100.         object FindProxyForURL(string url, string host);
  101.     }
  102.    
  103.     [ComImport()]
  104.     [Guid("BB1A2AE1-A4F9-11cf-8F20-00805F2CD064")]
  105.     [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
  106.     internal interface IActiveScript
  107.     {
  108.         void SetScriptSite(IActiveScriptSite pass);
  109.         void GetScriptSite(Guid riid, out IntPtr site);
  110.         void SetScriptState(ScriptState state);
  111.         void GetScriptState(out ScriptState scriptState);
  112.         void Close();
  113.         void AddNamedItem(string name, ScriptItem flags);
  114.         void AddTypeLib(Guid typeLib, uint major, uint minor, uint flags);
  115.         void GetScriptDispatch(string itemName, out IScript dispatch);
  116.         void GetCurrentScriptThreadID(out uint thread);
  117.         void GetScriptThreadID(uint win32ThreadId, out uint thread);
  118.         void GetScriptThreadState(uint thread, out ScriptThreadState state);
  119.         void InterruptScriptThread(uint thread, out EXCEPINFO exceptionInfo, uint flags);
  120.         void Clone(out IActiveScript script);
  121.     }
  122.    
  123.     [ComImport()]
  124.     [Guid("DB01A1E3-A42B-11cf-8F20-00805F2CD064")]
  125.     [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
  126.     internal interface IActiveScriptSite
  127.     {
  128.         void GetLCID(out int lcid);
  129.         void GetItemInfo(string name, ScriptInfo returnMask,         [Out()]
  130.         [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.IUnknown)]
  131. object[] item,         [Out()]
  132.         [MarshalAs(UnmanagedType.LPArray)]
  133. IntPtr[] typeInfo);
  134.         void GetDocVersionString(out string version);
  135.         void OnScriptTerminate(object result, EXCEPINFO exceptionInfo);
  136.         void OnStateChange(ScriptState scriptState);
  137.         void OnScriptError(IActiveScriptError scriptError);
  138.         void OnEnterScript();
  139.         void OnLeaveScript();
  140.     }
  141.    
  142.     internal enum UrlPolicy
  143.     {
  144.         DisAllow = 3
  145.     }
  146.    
  147.     [ComImport(), Guid("6D5140C1-7436-11CE-8034-00AA006009FA"), InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)]
  148.     internal interface IOleServiceProvider
  149.     {
  150.         [PreserveSig()]
  151.         int QueryService(        [In()]
  152. ref Guid guidService,         [In()]
  153. ref Guid riid,         [Out()]
  154. out IntPtr ppvObject);
  155.     }
  156.    
  157.     static internal class ComConstants
  158.     {
  159.         public const int INTERFACE_USES_SECURITY_MANAGER = 8;
  160.         // Object knows to use IInternetHostSecurityManager
  161.     }
  162.    
  163.     [ComImport()]
  164.     [Guid("CB5BDC81-93C1-11cf-8F20-00805F2CD064")]
  165.     [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
  166.     internal interface IObjectSafety
  167.     {
  168.         [return: MarshalAs(UnmanagedType.I4)]
  169.         [PreserveSig()]
  170.         int GetInterfaceSafetyOptions(ref Guid riid,         [Out()]
  171. out int pdwSupportedOptions,         [Out()]
  172. out int pdwEnabledOptions);
  173.        
  174.         [return: MarshalAs(UnmanagedType.I4)]
  175.         [PreserveSig()]
  176.         int SetInterfaceSafetyOptions(ref Guid riid, int dwOptionSetMask, int dwEnabledOptions);
  177.     }
  178.    
  179.     [ComImport()]
  180.     [Guid("3af280b6-cb3f-11d0-891e-00c04fb6bfc4")]
  181.     [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
  182.     internal interface IInternetHostSecurityManager
  183.     {
  184.         [return: MarshalAs(UnmanagedType.I4)]
  185.         [PreserveSig()]
  186.         int GetSecurityId(        [Out()]
  187. byte[] pbSecurityId,         [In(), Out()]
  188. ref IntPtr pcbSecurityId, IntPtr dwReserved);
  189.        
  190.         [return: MarshalAs(UnmanagedType.I4)]
  191.         [PreserveSig()]
  192.         int ProcessUrlAction(int dwAction,         [Out()]
  193. int[] pPolicy, int cbPolicy,         [Out()]
  194. byte[] pContext, int cbContext, int dwFlags, int dwReserved);
  195.        
  196.         [return: MarshalAs(UnmanagedType.I4)]
  197.         [PreserveSig()]
  198.         int QueryCustomPolicy(Guid guidKey,         [Out()]
  199. out byte[] ppPolicy,         [Out()]
  200. out int pcbPolicy, byte[] pContext, int cbContext, int dwReserved);
  201.     }
  202.    
  203.     [ComImport()]
  204.     [Guid("EAE1BA61-A4ED-11cf-8F20-00805F2CD064")]
  205.     [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
  206.     internal interface IActiveScriptError
  207.     {
  208.         void GetExceptionInfo(out EXCEPINFO exceptionInfo);
  209.         void GetSourcePosition(out uint sourceContext, out uint lineNumber, out int characterPosition);
  210.         void GetSourceLineText(out string sourceLine);
  211.     }
  212.    
  213.     [ComImport()]
  214.     [Guid("BB1A2AE2-A4F9-11cf-8F20-00805F2CD064")]
  215.     [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
  216.     internal interface IActiveScriptParse32
  217.     {
  218.         void InitNew();
  219.        
  220.         void AddScriptlet(string defaultName, string code, string itemName, string subItemName, string eventName, string delimiter, IntPtr sourceContextCookie, uint startingLineNumber, ScriptText flags, out string name,
  221.         out EXCEPINFO exceptionInfo);
  222.        
  223.         void ParseScriptText(string code, string itemName,         [MarshalAs(UnmanagedType.IUnknown)]
  224. object context, string delimiter, IntPtr sourceContextCookie, uint startingLineNumber, ScriptText flags,         [MarshalAs(UnmanagedType.Struct)]
  225. out object result, out EXCEPINFO exceptionInfo);
  226.     }
  227.    
  228.     [ComImport()]
  229.     [Guid("C7EF7658-E1EE-480E-97EA-D52CB4D76D17")]
  230.     [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
  231.     internal interface IActiveScriptParse64
  232.     {
  233.         void InitNew();
  234.        
  235.         void AddScriptlet(string defaultName, string code, string itemName, string subItemName, string eventName, string delimiter, IntPtr sourceContextCookie, uint startingLineNumber, ScriptText flags, out string name,
  236.         out EXCEPINFO exceptionInfo);
  237.        
  238.         void ParseScriptText(string code, string itemName,         [MarshalAs(UnmanagedType.IUnknown)]
  239. object context, string delimiter, IntPtr sourceContextCookie, uint startingLineNumber, ScriptText flags,         [MarshalAs(UnmanagedType.Struct)]
  240. out object result, out EXCEPINFO exceptionInfo);
  241.     }
  242.    
  243.     // Use this helper to deal with the fact that two interfaces with different Guids are required on 32 vs. 64 bit.
  244.     internal class ActiveScriptParseWrapper
  245.     {
  246.         private readonly IActiveScriptParse32 asp32;
  247.         private readonly IActiveScriptParse64 asp64;
  248.        
  249.         internal ActiveScriptParseWrapper(object comObject)
  250.         {
  251.             if (IntPtr.Size == 4) {
  252.                 asp32 = (IActiveScriptParse32)comObject;
  253.             }
  254.             else {
  255.                 asp64 = (IActiveScriptParse64)comObject;
  256.             }
  257.         }
  258.        
  259.         internal void InitNew()
  260.         {
  261.             if (asp32 != null) {
  262.                 asp32.InitNew();
  263.             }
  264.             else {
  265.                 asp64.InitNew();
  266.             }
  267.         }
  268.        
  269.         internal void AddScriptlet(string defaultName, string code, string itemName, string subItemName, string eventName, string delimiter, IntPtr sourceContextCookie, uint startingLineNumber, ScriptText flags, out string name,
  270.         out EXCEPINFO exceptionInfo)
  271.         {
  272.             if (asp32 != null) {
  273.                 asp32.AddScriptlet(defaultName, code, itemName, subItemName, eventName, delimiter, sourceContextCookie, startingLineNumber, flags, out name,
  274.                 out exceptionInfo);
  275.             }
  276.             else {
  277.                 asp64.AddScriptlet(defaultName, code, itemName, subItemName, eventName, delimiter, sourceContextCookie, startingLineNumber, flags, out name,
  278.                 out exceptionInfo);
  279.             }
  280.         }
  281.        
  282.         internal void ParseScriptText(string code, string itemName,         [MarshalAs(UnmanagedType.IUnknown)]
  283. object context, string delimiter, IntPtr sourceContextCookie, uint startingLineNumber, ScriptText flags,         [MarshalAs(UnmanagedType.Struct)]
  284. out object result, out EXCEPINFO exceptionInfo)
  285.         {
  286.             if (asp32 != null) {
  287.                 asp32.ParseScriptText(code, itemName, context, delimiter, sourceContextCookie, startingLineNumber, flags, out result, out exceptionInfo);
  288.             }
  289.             else {
  290.                 asp64.ParseScriptText(code, itemName, context, delimiter, sourceContextCookie, startingLineNumber, flags, out result, out exceptionInfo);
  291.             }
  292.         }
  293.     }
  294.    
  295.    
  296.     //
  297.     // COM Classes
  298.     //
  299.    
  300.     [ComImport()]
  301.     [Guid("f414c260-6ac0-11cf-b6d1-00aa00bbbb58")]
  302.     internal class JScriptEngine
  303.     {
  304.     }
  305. }
  306. #endif

Developer Fusion