zoukankan      html  css  js  c++  java
  • C#编写COM组件

    1、新建一个类库项目 

    2、将Class1.cs改为我们想要的名字 
    问是否同时给类改名,确定 


    3、修改Properties目录下面的AssemblyInfo.cs 
    ComVisible属性设置为True 


    4、项目菜单->MyLib属性 
    找到“生成”选项卡 

    往下看,找到“为 COM Interop 注册”勾上 


    5、继续往下,找到“签名”选项卡 
      勾上“为程序集签名” 
      在下面的下拉框里面选择“ <新建...>” 

    6、在弹出的对话框里面,输入MyLib。。或者随便取个名字 
      去掉使用密码保护文件的选项 

    7、开始编码,任何一个公开的类,必须有一个 I开通的接口定义 
    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Runtime.InteropServices;
    namespace MyLib {   [ComVisible(true)]   [Guid("2CBD3D76-35F1-4f9d-9C1B-9DBFEE412F76")]   public interface IMyClass
      {     
    void Initialize();     void Dispose();     int Add(int x, int y);   }   [ComVisible(true)]   [Guid("EA2F140A-108F-47ae-BBD5-83EEE646CC0D")]   [ProgId("MyLib.MyClass")]   public class MyClass : IMyClass   {     public void Initialize()     {       //nothing todo     }     public void Dispose()     {       //nothing todo     }     public int Add(int x, int y)     {       return x + y;     }   } }
    8、GUID属性里面的那个字符串,在“工具”菜单下面,“创建 GUID” 
      选择 Registry Format,然后复制 
      
      注意在[Guid("....... 这个里面要去掉GUID前后的花括号 

    9、编译它 
    在命令提示符下面,进入Dll所在的目录 
    用 gacutil /i MyLib.dll 将这个DLL加入的全局缓存里 
    然后用 regasm MyLib.dll 注册这个dll 

    10、在javsScript里面试试.
     
  • 相关阅读:
    Primitive Roots POJ
    [kuangbin带你飞]专题十四 数论基础 A
    计蒜客 最长不下降子序列 (贪心+二分nlogn算法)
    [kuangbin带你飞]专题十二 基础DP1 N
    hdu 2527 Safe Or Unsafe (优先队列实现Huffman)
    nyoj 991-Registration system (map)
    hdu 1075 What Are You Talking About (map)
    hdu 1263 水果 (嵌套 map)
    hdu 1556 Color the ball (技巧 || 线段树)
    hdu 2896 病毒侵袭 (AC自动机)
  • 原文地址:https://www.cnblogs.com/liaocheng/p/4243983.html
Copyright © 2011-2022 走看看