swig实现c#和c++之间的函数调用
背景
- 用swig编写胶水代码
- c#加载dll(或者其他c++的库,比如.a .so),然后c++回调c#中的方法
实现
c层实现
typedef void(*pCBFunc)(bool success);
extern "C" {
    virtual void CPP_InitData(pCBFunc cb);
}
c#层实现
public class PointerTest
{
    public delegate void InitDelegate(bool success);
    public SWIGTYPE_p_f_bool_void m_initDelegate = null;
    public void Work(InitDelegate cb)
    {
        m_initDelegate = new SWIGTYPE_p_f_bool_void(Marshal.GetFunctionPointerForDelegate(cb), false);
        CPP_InitData(m_initDelegate);
    }
}

 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号