添加连接点不会生成fire_ *方法

问题描述

我正在尝试在Visual Studio 2019中的ATL项目上创建回调函数。当我使用“添加连接点”时,Visual Studio(2017和2019)不会在CProxy_ * Events中生成fire_ *方法

请帮助解决此问题。

解决方法

ConnectionPoint 错误是旧的 Visual Studio 错误。我展示了我的 Fire_* 方法。将其插入到您的 CProxy_* 类中:

HRESULT Fire_On/*event_name*/(/*args list*/) 
{
    HRESULT hr = S_OK;
    T* pThis = static_cast<T*>(this);
    int cConnections = m_vec.GetSize();
    for (int iConnection = 0; iConnection < cConnections; iConnection++)
    {
        pThis->Lock();
        CComPtr<IUnknown> punkConnection = m_vec.GetAt(iConnection);
        pThis->Unlock();
        IDispatch* pConnection = static_cast<IDispatch*>(punkConnection.p);

        if (pConnection) 
        {
            CComVariant avarParams[/*count of args list*/];
            avarParams[0] = /*arg from args list*/;
            avarParams[1] = /*arg from args list*/;
            /*other params*/
            avarParams[/*N-1*/] = /*arg from args list*/;
            DISPPARAMS params = { avarParams,nullptr,/*count of args list*/,0 };
            hr = pConnection->Invoke(/*number of function*/,IID_NULL,LOCALE_USER_DEFAULT,DISPATCH_METHOD,&params,nullptr);
        }
    }
    return hr;
}