문제

I need to consume a C# class from an unmanaged application. Say I have the following C# class:

public class Managed
{
    public void Subcribe(int handler)
    {
        ....
    }
}

Then I create the following C++/CLI class:

/// Header
class Mixed
{
public:
    void Subscribe(int handler);
private:
    class MixedImp;
    MixedImp* m_implementation;
}

/// CPP
ref class MixedImp
{
public:
    void Subscribe(int handler)
    {
        m_accessor->Subscribe(handler);
    }
private:
    Managed^ m_accessor;
}

Mixed::Subcribe(int handler)
{
    m_implementation->Subcribe(handler)
}

When doing this I get a pointer to incomplete class type is not allowed so I'm not getting something. I'm not a natural unmanaged developer so forgive me if the question is somewhat silly :\

도움이 되었습니까?

해결책

#include <vcclr.h>


class Mixed
{
public:
  void Subscribe(int handler)
  {
    m_accessor->Subscribe(handler);
  }
private:
  gcroot<Managed^> m_accessor;
};
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top