cs中访问COM的方法

Type t = Type.GetTypeFromProgID("ActiveXTestLib.MyAxControlTest");
object o = System.Activator.CreateInstance(t);

 

 

    [Guid("D6F88E95-8A27-4ae6-B6DE-0542A0FC7039")]
    [InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
    public interface _Functions
    {
        [DispId(1)]
        string DoSearch(string query, int resultsnum);
    }

 

 

[GuidAttribute("8173BE03-E29B-49CB-A4B4-52778F6E37E5"),
    ProgId("ActiveXTestLib.MyAxControlTest")
]
    public partial class MyAxControlTest : UserControl, IObjectSafety, _Functions

{

 

 

。。。。。。。。。。

 //interface
        public string DoSearch(string query, int resultsnum)
        {
            //example code

            return "abbbbhnm";
        }


       ///////

。。。。。。。。。。。

#region IObjectSafety Members

        public int GetInterfaceSafetyOptions(ref Guid riid, ref int pdwSupportedOptions, ref int pdwEnabledOptions)
        {
            pdwSupportedOptions = 1;
            pdwEnabledOptions = 2;
            return 0;
        }

        public int SetInterfaceSafetyOptions(ref Guid riid, int dwOptionSetMask, int dwEnabledOptions)
        {
            return 0;
        }

        #endregion


}

posted @ 2011-09-23 12:23  dingqiuMaster  阅读(202)  评论(0编辑  收藏  举报