// C++
class MustInherit { public: virtual void DoExec() = 0; };
// C++/CLI
public ref class Proxy abstract {
public:
     virtual void DoExec() = 0;
     static IntPtr CreateInstance(Proxy^ proxy) {
         return IntPtr((void*)new Inherited(proxy));
     }
     static void DeleteInstance(IntPtr proxy) {
         delete (Inherited*)proxy.ToPointer();
     }
};
#include <vcclr.h>
class Inherited : public MustInherit {
&nbsp; &nbsp; gcroot<Proxy^> m_proxy;
public:
&nbsp; &nbsp; Inherited(Proxy^ proxy) : m_proxy(proxy) { }
&nbsp; &nbsp; virtual void DoExec() { this->m_proxy->DoExec(); }
};
// C#
public class Overrider : Proxy {
&nbsp; &nbsp; public override void DoExec() { Console.WriteLine("exec"); }
}
[DllImport("sample.dll")]
static extern void CallbcakTest(IntPtr mustInherit);
void Test() {
&nbsp; &nbsp; var overrider = new Overrider();
&nbsp; &nbsp; IntPtr callback = Proxy.CreateInstance(overrider);
&nbsp; &nbsp; CallbackTest(callback);
&nbsp; &nbsp; Proxy.DeleteInstance(callback);
}