利用.net创建安全COM控件

创建控件,其实就是创建一个dll,把他注册成COM  控件,并给它导入安全接口。
(安全是指在调用是不会弹出安全对话框)

using System;<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

using System.Runtime.InteropServices;

 

namespace openOffice

{

     /// <summary>

     /// IObjectSafety 的摘要说明。

     /// </summary>

     [Guid("CB5BDC81<?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" />-93C1-11CF-8F20-00805F2CD064"),InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]

     public interface IObjectSafety

     {

         // methods

         void GetInterfacceSafyOptions(

              System.Int32 riid,

              out System.Int32 pdwSupportedOptions,

              out System.Int32 pdwEnabledOptions);

         void SetInterfaceSafetyOptions(

              System.Int32 riid,

              System.Int32 dwOptionsSetMask,

              System.Int32 dwEnabledOptions);     

     }

}

 

using System;

using System.Collections.Generic;

using System.Text;

using System.Windows.Forms;

using System.Runtime.InteropServices;

using Word = Microsoft.Office.Interop.Word;

using Excel = Microsoft.Office.Interop.Excel;

using OpenOffice.localhost;

using System.Net;

using System.IO;

 

namespace openOffice

{

    [Guid("B783512A-CA69-4b1e-97D7-1EC0FAEFC13B"), ProgId("openOffice.DmosClient")]

    public class DmosClient : IObjectSafety, IDmosClient

    {

        public void ShowMessage(string msg)

        {

            MessageBox.Show(msg);

        }

 

        #region IObjectSafety 成员

 

        public void GetInterfacceSafyOptions(Int32 riid, out Int32 pdwSupportedOptions, out Int32 pdwEnabledOptions)

        {

            // TODO:  添加WebCamControl.GetInterfacceSafyOptions 实现

            pdwSupportedOptions = CLsObjectSafety.INTERFACESAFE_FOR_UNTRUSTED_CALLER;

            pdwEnabledOptions = CLsObjectSafety.INTERFACESAFE_FOR_UNTRUSTED_DATA;

        }

 

        public void SetInterfaceSafetyOptions(Int32 riid, Int32 dwOptionsSetMask, Int32 dwEnabledOptions)

        {

            // TODO:  添加WebCamControl.SetInterfaceSafetyOptions 实现             

        }

 

        #endregion

 

    }

}

 

using System;

 

namespace openOffice

{

     /// <summary>

     /// CLsObjectSafety 的摘要说明。

     /// </summary>

     public class CLsObjectSafety

     {

         public const System.Int32 INTERFACESAFE_FOR_UNTRUSTED_CALLER = 0x00000001;

         public const System.Int32 INTERFACESAFE_FOR_UNTRUSTED_DATA = 0x00000002;

     }

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值