简体   繁体   中英

Add Connection Points doesn't generate fire_* methods

I'm trying to create callback function on ATL project in Visual Studio 2019. When I use "Add Connection Point", Visual Studio (2017 and 2019) does not generate fire_* methods in CProxy_*Events.

Please help solve this problem.

ConnectionPoint bug is old Visual Studio bug. I show my Fire_* method. Insert it into your CProxy_* class:

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, nullptr, nullptr);
        }
    }
    return hr;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM