Wrapping boost::function with a C++/CLI class event

I'm trying to figure out how to wrap a boost::function member (used as an event callback) of an unmanaged class with a C++/CLI class event. I do not have control over the unmanaged class. All I can do is figure out how to write the C++/CLI class properly.

Here's the example unmanaged class:

class X
{
public:
    boost::function<void (double)> XChanged;;

    void Set(double x)
    {
        XChanged(x)
    }
};

I've tried many things, but I keep running into problems. I'm sure it's easier than it appears to be. Any help would be greatly appreciated!


CLI probably won't let you declare a boost::function as a static member. Make it a pointer:

boost::function<void(double> *XChanged;

Then allocate/deallocate in the constructor and finalizer and call it with (*XChanged)(arg);

链接地址: http://www.djcxy.com/p/27800.html

上一篇: 用C ++ / CLI包装非托管C ++类库

下一篇: 用C ++ / CLI类事件包装boost :: function