使用纯虚方法包装类

我有一个非托管的DLL,它包含一个只有纯虚方法的类(回调类型):

class PAClient { public: __declspec(dllexport) virtual void SetCalculationStarted() = 0; __declspec(dllexport) virtual void SetCalculationStopped() = 0; } 

现在我必须将这些函数调用发送到托管C#代码并决定使用接口。 这就是我所做的:

 public interface class IPAClientWrapper { void SetCalculationStarted(); void SetCalculationStopped(); }; private class PAClientWrapper : public PAClient { private: gcroot callBack; public: PAClientWrapper(IPAClientWrapper^ c) { callBack = c; } void SetCalculationStarted() { callBack->SetCalculationStarted(); } void SetCalculationStopped() { callBack->SetCalculationStopped(); } } 

但每次调用非托管的 SetCalculationStarted() ,非托管代码都会抛出exception:

 An unhandled exception of type 'System.AccessViolationException' occurred in PAnalysisLib.dll Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt. 

编辑:

 public partial class Form1 : Form, IPAClientWrapper { public Form1() { InitializeComponent(); } public void SetCalculationStarted() { Console.WriteLine("started"); } public void SetCalculationStopped() { Console.WriteLine("stopped"); } 

}

我错过了什么吗?