How to consume a C# class from C++/CLI using PIMPL
-
22-06-2021 - |
문제
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;
};
제휴하지 않습니다 StackOverflow