Cannot use managed event/objects in unmanaged code error c3265, c2811

蹲街弑〆低调 提交于 2019-11-30 23:05:47

Your native class needs to store a handle to the managed object instead of a reference to it. You can do this using the gcroot template. If you dig into the gcroot template you will find it uses the GCHandle Structure, which with appropriate static casting can be stored as a void* pointer and so provides a means of storing managed references in native code.

Try expanding your code along the following lines:

#include <vcclr.h>

class MyNativeListener: public NativeEventListener
{ 
private:
    gcroot<ManagedResultsObject^> _results;
public:
    void onEndProcessing(ProcessingEvent *event) 
    {
        _results->Value = event->value;
        //Many more properties to capture
    }
};
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!