http://mixy.egloos.com/953406

    /// <summary>
    /// See Internet SDK, IObjectSafety.
    /// </summary>
    [Flags]
    public enum ObjectSafetyFlags : int
    {
        /// <summary>

        /// Caller of interface may be untrusted
        /// </summary>
        INTERFACESAFE_FOR_UNTRUSTED_CALLER = 1,

        /// <summary>
        /// Data passed into interface may be untrusted
        /// </summary>
        INTERFACESAFE_FOR_UNTRUSTED_DATA = 2,

        /// <summary>
        /// Object knows to use IDispatchEx.
        /// </summary>
        INTERFACE_USES_DISPEX = 4,

        /// <summary>
        /// Objects knows to use IInternetHostSecurityManager.
        /// </summary>
        INTERFACE_USES_SECURITY_MANAGER = 8,

        /// <summary>
        /// Flags combination.
        /// </summary>
        SafeForScripting = INTERFACESAFE_FOR_UNTRUSTED_CALLER |
        INTERFACESAFE_FOR_UNTRUSTED_DATA
    }

    [ComImport]
    [Guid("CB5BDC81-93C1-11cf-8F20-00805F3CD064")]
    [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
    public interface IObjectSafety
    {
        void GetInterfaceSafetyOptions(ref Guid riid, out int supportedOptions, out int enabledOptions);
        void SetInterfaceSafetyOptions(ref Guid riid, int optionSetMask, int enabledOptions);
    }
    [Guid("5E603C7D-4B7C-412a-BAB4-064E5674F97A")]
    [InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
    [ComVisible(true)]
    public interface IActiveXControl_Method
    {
        [DispId(1)]
        string dispFunction(string str);
    }

[ProgId("TestServer.ActiveX")]
    [ComVisible(true)]
    [ClassInterface(ClassInterfaceType.AutoDual)]
    [Guid("D2BD9E76-C60B-4724-B44E-986132D8FA7A")]
    public partial class Server : UserControl, IActiveXControl_Method, IObjectSafety
    {
        #region For Registration
        [ComRegisterFunction()]
        public static void RegisterClass(string key)
        {
            //Strip off HKEY_CLASSES_ROOT\ from the passed key as I don't need it
            StringBuilder sb = new StringBuilder(key);
            sb.Replace(@"HKEY_CLASSES_ROOT\", "");

            //Open the CLSID\{guid} key for write access
            RegistryKey k = Registry.ClassesRoot.OpenSubKey(sb.ToString(), true);

            //And create the 'Control' key - this allows it to show up in
            //the ActiveX control container
            RegistryKey ctrl = k.CreateSubKey("Control");

            ctrl.Close();

            //Next create the CodeBase entry - needed if not string named and GACced.
            RegistryKey inprocServer32 = k.OpenSubKey("InprocServer32", true);
            inprocServer32.SetValue("CodeBase", Assembly.GetExecutingAssembly().CodeBase);
            inprocServer32.Close();

            //Finally close the main key
            k.Close();
        }

        [ComUnregisterFunction()]
        public static void UnregisterClass(string Key)
        {
            StringBuilder sb = new StringBuilder(Key);
            sb.Replace(@"HKEY_CLASSES_ROOT\", "");

            //Open HKCR\CLSID\{guid} for write access
            RegistryKey k = Registry.ClassesRoot.OpenSubKey(sb.ToString(), true);

            //Delete the 'Control' key, but don't throw an exception if it does not exist
            k.DeleteSubKey("Control", false);

            //Next open InprocServer32
            RegistryKey inprocServer32 = k.OpenSubKey("InprocServer32", true);

            //And delete the CodeBase key, again not throwing if missing
            k.DeleteSubKey("CodeBase", false);

            //Finally close the main key
            k.Close();
        }
        #endregion

        #region IObjectSafety 멤버
        public void GetInterfaceSafetyOptions(ref Guid riid, out int supportedOptions, out int enabledOptions)
        {
            supportedOptions = enabledOptions = (int)ObjectSafetyFlags.SafeForScripting;
        }

        public void SetInterfaceSafetyOptions(ref Guid riid, int optionSetMask, int enabledOptions)
        {
        }
        #endregion

        string m_strSavePath = System.Environment.GetFolderPath(Environment.SpecialFolder.Templates);

        public Server()
        {
            InitializeComponent();
        }

        #region IActiveX_Method
        public string dispFunction(string str)
        {
                       string strRes;

                        return strRes;
        }
        #endregion
  }

+ Recent posts