none
c++ callback 函数 转 c# RRS feed

  • 问题

  •  

    这是c++的回调函数:

    Code Snippet
    // Callback functions.
    void SetMessageProcessCallback(void* pUserObject_, void (*pfUserMessageProcessFunc_)(void*,AMC_MESG*));

    __fastcall TFormProprioWare::TFormProprioWare(TComponent* Owner)
    {
      SetMessageProcessCallback((void *)this, &MesgProcessCallback);
    }

    void MesgProcessCallback(VOID* MyObjPtr, AMC_MESG* pclMesg_)
    {
      ((TFormProprioWare*)MyObjPtr)->ProcessMesg(pclMesg_);
    }

    void TFormProprioWare::ProcessMesg(AMC_MESG *pclMesg_)
    {}

     

     


    下面是我转的代码:

    Code Snippet
    [DllImport(Constant.Dllname_amc)]
    public extern static void SetMessageProcessCallback(object sender, SetMessageCallback DelegateFunc);
    [DllImport(Constant.Dllname_amc)]
    public extern static void SetByteProcessCallback(object sender, SetByteCallback DelegateFunc);

    public delegate void SetMessageCallback(object sender, ref AMC_MESG amc);
    public delegate void SetByteCallback(object sender,byte ucByte);

    SetMessageCallback callback1 = ProcessCallback.MesgProcessCallback;
    SetByteCallback callback2 = ProcessCallback.ByteProcessCallback;
               
    SetMessageProcessCallback(this, callback1);
    SetByteProcessCallback(this, callback2);

    public static void MesgProcessCallback(object sender, ref AMC_MESG amc)
    {}
    public static void ByteProcessCallback(object sender,byte ucByte_){}

     

     

    可当控件的属性被修改时,这两个回调函数MesgProcessCallback 和 ByteProcessCallback 并不执行,请高手帮忙。
    我想是不是动态库Constant.Dllname_amc没有被倒入内存中,所以它里面的线程没有启动的原因???

    2008年12月11日 3:36

答案