我用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'
{
[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'
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
}
以前使用C#写的Com,使用Delphi6和Delphi7调用都不行。