非托管C++代码:
class CPLUSALOG_API_20211029 CCTest
{
public:
    CCTest();
    int* Get();
    ~CCTest();
protected:
    Hobject* m_pRegion;
}
  CCTest::CCTest()
{
    m_pRegion = new Hobject();
    Halcon::gen_circle(m_pRegion, 10.0, 10, 10);
}
int* CCTest::Get()
{
    return (int*)m_pRegion->Id();
}

CCTest::~CCTest()
{
    delete m_pRegion;
}
C#代码:
 public class CTest
    {
       public CTest(System.IntPtr ptr)
        {
            m_region = new HObject(ptr);
            HTuple tArea, tRow, tCol;
            HOperatorSet.AreaCenter(m_region, out tArea, out tRow, out tCol);
        }
        HObject m_region;
    }
调用方,托管C++代码:
     CCTest ctest;
             ProjectBaseLib::NGClass::CTest^ test = gcnew ProjectBaseLib::NGClass::CTest((System::IntPtr)ctest.Get());

调用结果:
面积:314

posted on 2022-11-16 15:16  闻缺陷则喜何志丹  阅读(26)  评论(0编辑  收藏  举报  来源