我目前有一个悬而未决的问题- 但是在处理它之后我遇到了一个新问题,我在尝试构建它时遇到的错误是:
Error 1 error C2695: 'MyEventsSink::OnSomethingHappened': overriding virtual function differs from 'Library::IEventsSink::OnSomethingHappened' only by calling convention
Error 2 error C2695: 'MyEventsSink::SomeTest': overriding virtual function differs from 'Library::IEventsSink::SomeTest' only by calling convention
我试着对这个错误进行观察,但我无法弄清楚。
这就是我正在做的事情,我有一个托管的 C# dll 类库,它正在被本机 C++ 应用程序使用。C#接口的代码如下,该接口的实现是C++。
C#代码是
[ComVisible(true), ClassInterface(ClassInterfaceType.None), Guid("fdb9e334-fae4-4ff5-ab16-d874a910ec3c")]
public class IEventsSinkImpl : IEventsSink
{
public void OnSomethingHappened()
{
//Doesnt matter what goes on here - atleast for now
}
public void SomeTest(IEventsSink snk)
{
//When this is called - it will call the C++ code
snk.OnSomethingHappened();
}
}//end method
它在 C++ 中的实现代码是
class MyEventsSink : public Library::IEventsSink
{
public:
MyEventsSink() {}
~MyEventsSink() {}
virtual HRESULT OnSomethingHappened()
{
std::cout << "Incredible - it worked";
}
virtual HRESULT SomeTest(IEventsSink* snk)
{
//Doesnt matter this wont be called
}
};
显然在构建过程中 VS2010 抱怨上述错误。关于如何解决这些错误的任何建议。