接口不能从非接口的IDispatch继承

Interface cannot inherit from non-Interface IDispatch

本文关键字:接口 IDispatch 继承 不能      更新时间:2023-10-16

我是一个c++新手(从1.0测试版开始就在做c#)。我被分配将一个小的c++解决方案从VS 2005升级到VS 2015(它生成一个。ocx文件)。到目前为止,大部分都很好,除了一段疯了。

我有错误"接口类'IEmail'不能从非接口类'IDispatch'继承"

__interface IEmail : IDispatch
{
    [id(1), helpstring("method Send")] HRESULT Send(BSTR SenderName, BSTR Sender, BSTR Recipient, BSTR Subject, BSTR Message,BSTR Server);
    [id(2), helpstring("method Shutdown")] HRESULT Shutdown(void);
    [id(3), helpstring("method Listen")] HRESULT Listen(BSTR Server, BSTR Account, BSTR Password);
    [id(4), helpstring("method DebugMode")] HRESULT DebugMode(LONG nMode);
};

IDispatch被定义为

    typedef interface IDispatch IDispatch;

谁能告诉我如何得到什么旧代码是完成,再次工作?(简单地用c++语言解释给我听,可能行不通)

vc++有一些扩展,包括c++的代码属性系统,可以直接从c++代码中生成COM类型信息。作为这些扩展的一部分,__interface标识了一个纯虚拟类,它是一个COM接口。

这不是一个托管接口,这是一个非托管接口:https://msdn.microsoft.com/en-us/library/50h7kwtb(v=vs.80).aspx

简而言之,__interface是正确的,而interface不是。因为你有那个typedef,它看起来像一些编译器选项或编译标志是错误的,它试图编译托管c++/CLR代码。