和我一起学VSTA(Visual Studio Tools for Applications )(四)

和我一起学VSTA(Visual Studio Tools for Applications )(四)前三篇简单介绍了 VSTA 的用途以及开发前期准备 这一篇将介绍具体的开发 我们先实现一个最简单的功能 打开 VSTA IDE 编程环境 首先在 VSTASAMPLE 项目中 添加如下引用 以及 Microsoft Development Enviroment 8 0

大家好,我是讯享网,很高兴认识大家。

前三篇简单介绍了VSTA的用途以及开发前期准备,这一篇将介绍具体的开发。

我们先实现一个最简单的功能,打开VSTA IDE编程环境。

首先在VSTASAMPLE项目中,添加如下引用:

 


讯享网 

以及:

Microsoft Development Enviroment 8.0.

DTEProvider 1.0 Type Library

 

添加HostItemProvider.cs,代码如下:

 

 1 using  System;
 2 using  System.Collections.Generic;
 3 using  System.Text;
 4 using  System.AddIn.Contract;
 5 using  System.AddIn.Contract.Automation;
 6 using  System.Runtime.Remoting;
 7 using  Microsoft.VisualStudio.Tools.Applications.Contract;
 8 using  Microsoft.VisualStudio.Tools.Applications;
 9
10 namespace  VSTASample
11 ExpandedBlockStart.gif {
12    internal class HostItemProvider : ContractAdapterBase,
13    IHostItemProviderContract
14ExpandedSubBlockStart.gif    {
15        private VSTAApplication application;
16
17        public HostItemProvider( VSTAApplication application,
18            TypeInfrastructureManager typeInfrastructureManager )
19            : base(typeInfrastructureManager)
20ExpandedSubBlockStart.gif        {
21            this.application = application;
22        }

23
24        protected override IContract QueryContract( string contractId )
25ExpandedSubBlockStart.gif        {
26            if(String.Compare(contractId,
27                typeof(IHostItemProviderContract).AssemblyQualifiedName,
28                StringComparison.Ordinal) == 0)
29ExpandedSubBlockStart.gif            {
30                return (IContract)this;
31            }

32
33            return base.QueryContract(contractId);
34        }

35
36        public IRemoteObjectContract GetHostObject( string objectType, string cookie )
37ExpandedSubBlockStart.gif        {
38            if(String.Compare(objectType,
39                typeof(RCS.Common.VSTA.VSTAApplication).FullName,
40                StringComparison.Ordinal) == 0)
41ExpandedSubBlockStart.gif            {
42                RemoteObjectAdapter adapter = new RemoteObjectAdapter(
43                    typeof(RCS.Common.VSTA.VSTAApplication),
44                    application, TypeInfrastructureManager);
45                return adapter;
46            }

47
48            throw new ArgumentOutOfRangeException();
49        }

50
51        protected override string RemoteToString()
52ExpandedSubBlockStart.gif        {
53            return this.ToString();
54        }

55
56        protected override int GetRemoteHashCode()
57ExpandedSubBlockStart.gif        {
58            return this.GetHashCode();
59        }

60
61        protected override bool RemoteEquals( IContract contract )
62ExpandedSubBlockStart.gif        {
63            if(contract == null)
64                return false;
65
66            if(!System.Runtime.Remoting.RemotingServices.
67                IsObjectOutOfAppDomain(contract))
68ExpandedSubBlockStart.gif            {
69                HostItemProvider contractAdapter =
70                    contract as HostItemProvider;
71                return this.Equals(contractAdapter);
72            }

73
74            return false;
75        }

76    }

77}

78
小讯
上一篇 2025-02-16 07:03
下一篇 2025-01-06 16:52

相关推荐

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/30740.html