c#开发Com组件

来源:互联网 发布:移动有没有3g网络 编辑:程序博客网 时间:2024/05/10 21:39

1,定义接口

(1)在接口上方加上[Guid("1EA4DBF0-3C3B-11CF-810C-00AA00389B71")]

(2)在每个方法上加上[DispId(i)]
 

using System;
using System.Runtime.InteropServices;
namespace Leading.Mis.NewsMonitor
...
{
    
/**//// <summary>
    
/// 消息监控接口的定义
    
/// </summary>

    [Guid("1EA4DBF0-3C3B-11CF-810C-00AA00389B71")]
    
public interface INewsMonitor
    ...
{
        发送文件时,记录发送者,接收者和发送的文件名
发送文件时,记录发送者,接收者和发送的文件名
        
        接收文件时,记录文件接收者,发送者和发送的文件名
接收文件时,记录文件接收者,发送者和发送的文件名
        
        文件发送成功后,记录发送者,接收者和发送的文件名
文件发送成功后,记录发送者,接收者和发送的文件名
        
        取消文件发送时,记录发送者,接收者和发送的文件名
取消文件发送时,记录发送者,接收者和发送的文件名
        
    }
 // end interface INewsMonitor
    
}
 //end namespace Leading.Mis.NewsMonitor

 

2,类的实现

(1)在类的上方加上 [Guid("1EA4DBF0-3C3B-11CF-810C-00AA00389B71")]
                      [ClassInterface(ClassInterfaceType.None)]

 

using System;
using System.IO;
using System.Runtime.InteropServices;

namespace Leading.Mis.NewsMonitor
...
{
    
/**//// <summary>
    
/// 消息监控类的实现
    
/// </summary>

    [Guid("1EA4DBF0-3C3B-11CF-810C-00AA00389B71")]
    [ClassInterface(ClassInterfaceType.None)]
    
public class NewsMonitor : INewsMonitor
    ...
{
        
私有字段

        
私有方法
        
        
共有方法 
    }
 // end class NewsMonitor
    
}
 //end namespace Leading.Mis.NewsMonitor

 

3,用 Regasm 工具进行注册

Regasm NewsMsg.dll / tlb: NewsMsg.tlb