我用C#写了一个简单的COM,代码如下,已经生成lib和dll,然后在bcb6调用,使用import type library其lib文件,然后再create unit,之后我就不会了C#的com代码:namespace MyCom
{
  [Guid("7aa48830-bf92-4d16-8ace-9d30e46812c1")]  public interface MyCom_Interface
  {
  [DispId(1)]
  int Add(int a, int b);
  }  [Guid("9B22939B-9077-412d-969B-46726E1C638A"), InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
    
  public interface MyCom_Events
  {  }  [Guid("B3F60734-6B5B-4ba4-8A00-BE5B02D17CF7"),  ClassInterface(ClassInterfaceType.None),  ComSourceInterfaces(typeof(MyCom_Events))]  public class Class1:MyCom_Interface
  {
  public int Add(int a, int b)
  {
  return a + b;
  }
  }
}
---------------------------------------------------------------------------------------bcb6我尝试以下代码调用:MyCom_Interface aa;   结果提示:[C++ Error] Unit1.cpp(21): E2352 Cannot create instance of abstract class 'MyCom_Interface'
[C++ Error] Unit1.cpp(21): E2353 Class 'MyCom_Interface' is abstract because of '__stdcall MyCom_Interface::Add(long,long,long *) = 0'

解决方案 »

  1.   

    给你个我测试的例子,你应该能看出你的问题所在[ComVisible(true)]
      public interface IMath
      {
      [DispId(1)]
      int Add(int a, int b);  [DispId(2)]
      int Sub(int a, int b);
      }[ComVisible(true)]
      [ClassInterface(ClassInterfaceType.None)]
      public class Dotnet :ServicedComponent, IMath
      {
      #region IMath 成员  public int Add(int a, int b)
      {
      return a+b;
      }  public int Sub(int a, int b)
      {
      return a - b;
      }  #endregion
      } 
      

  2.   

    少了这个:[ComVisible(true)]
      

  3.   

    C#写东西,最好使用更高版本的BCB编译处理。
    以前使用C#写的Com,使用Delphi6和Delphi7调用都不行。
      

  4.   

    to:sdl2005lyx你认为我的bcb调用代码没有写错,只是错在C#那部分?
      

  5.   

    告诉你验证你的com组件是否正确方法:用VC6的一个工具“OLE View”,打开你com的dll,看看里面的方法是否正确!还有,你把我的例子,测试一下,看看会不会有问题,如果没有问题,你把我们两者之间的差别一项一项对比。