https://blog.csdn.net/weixin_38452552/article/details/79415275看了这个博主的方法,这个时js调用,想请教各位,在MFC里这种方法是否可行,可行的话如何实现。
我的实现:
在QTActive中:
int FindDialog:: AttachEvent(const QString& eventName, IDispatch* dispFunc)
{
    QMessageBox::information(NULL, "Title","[ActiveQtServerCallBack::AttachEvent]->eventName[" +eventName +"]");
    if (NULL == dispFunc)
    {
        QMessageBox::information(NULL, "Title", "[ActiveQtServerCallBack::AttachEvent]->dispFunc is NULL!!!");
        return -1;
    }
    QMessageBox::information(NULL, "Title", "3");     dispFunc->AddRef();
     m_pDispatch = dispFunc;
   // ui.btn_transmit->setEnabled(true);
  //  this->m_strCallBackContent = eventName;
   // QMessageBox::information(NULL, "Title", "4");    return 0;
}
在MFC中:
这个时生成的类中方法:
long AttachEvent(LPCTSTR p_eventName, LPDISPATCH p_dispFunc(int&, int&, int &, CString &))
{
long result;
static BYTE parms[] = VTS_BSTR VTS_DISPATCH;
InvokeHelper(0x39, DISPATCH_METHOD, VT_I4, (void*)&result, parms, p_eventName, p_dispFunc);
return result;
}
调用:
void CMFCTestCOMDlg::OnBnClickedButton3()
{
// TODO: 在此添加控件通知处理程序代码
UpdateData(true);

 
fdtest.AttachEvent(callbackContent, ActiveQtServerCallBackTrainsmitTest);
}
static LPDISPATCH ActiveQtServerCallBackTrainsmitTest(int &x, int &y, int &z, CString &strEvent)
{
CString str;
str.Format(_T("ActiveQtServerCallBackTrainsmitTest:\r\nx[%d]\r\ny[%d]\r\nz[%d]\r\nstrEvent[%s]"), x, y, z, strEvent);
AfxMessageBox(str);
return 0;
}