我按照网上提示方法用C#做了一个最简单的COM DLL :
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;namespace ClassLibrary1
{
    [Guid("154BD6A6-5AB8-4d7d-A343-0A68AB79470B")]
    public interface MyCom_Interface 
    {
        [DispId(1)]          
        int Add(int a, int b);     
    }    [Guid("D11FEA37-AC57-4d39-9522-E49C4F9826BB"), InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
    public interface MyCom_Events { }    [Guid("2E3C7BAD-1051-4622-9C4C-215182C6BF58"), ClassInterface(ClassInterfaceType.None), ComSourceInterfaces(typeof(MyCom_Events))]
    public class Class1 : MyCom_Interface
    { 
        public int Add(int a, int b) 
        { return a + b; } 
    }  
}
此外,还做了如下工作:
1 包含了密钥文件
2 项目属性->应用程序->程序集信息->选中“使程序集COM可见”。
3 项目属性->生成->选中“为COM互操作注册”。编译后,debug目录下有一个tlb文件和一个DLL文件。最后我将DLL文件复制到C:\windows\system32目录下。运行:Regsvr32 xxx.DLL系统提示:已加载xxx.dll,没有找到dllregisterserver输入点请问为什么我做的COM不能注册?不注册能使用吗?

解决方案 »

  1.   

    自己解决了:感谢您使用微软产品。   
        
      您可以使用regasm.exe来注册.NET   组件,regsvr32并不适用于.NET组件。   
      (或者您也可以将regasm.exe理解为.NET的regsvr32)   
      希望能对您有所帮助!   
        
        
      ======================   
      -   微软全球技术中心   
        
      本贴子仅供CSDN的用户作为参考信息使用。其内容不具备任何法律保障。您需要考虑到并承担使用此信息可能带来的风险。具体事项可参见使用条款(http://support.microsoft.com/directory/worldwide/zh-cn/community/terms_chs.asp)。   
      为了为您创建更好的讨论环境,请参加我们的用户满意度调查(http://support.microsoft.com/directory/worldwide/zh-cn/community/survey.asp?key=(S,49854782))。   
      ======================
      

  2.   

    COM组件应该是需要先注册才能使用的。注册组件时,RegSvr32需要调用DLL中的DllRegisterServer入口函数。
    反注册时,需要调用DLL中的DllUnregisterServer入口函数。