CONNECT_E_CANNOTCONNECT Error
The CONNECT_E_CANNOTCONNECT error is returned when AtlAdvise() calls the IConnectionPoint::Advise() method and fails. The ATL implementation of the IConnectionPointImpl::Advise() function calls QueryInterface() on the sink object (the client), looking for the event interface, and returns this error if it doesn't find it.
CONNECT_E_CANNOTCONNECT Error
For the CONNECT_E_CANNOTCONNECT error, verify that the event interface is in the sink, or client, COM map, as in the following example:
BEGIN_COM_MAP(CDispSink)
COM_INTERFACE_ENTRY(IDispatch)
COM_INTERFACE_ENTRY_IID(DIID__MySourceEvents, IDispatch)
END_COM_MAP()
Another cause of failure might be that the event interface is a custom interface and the source, or server, is out of process (an .exe file). You need to install a marshaler for the custom interface for QueryInterface() to work across process boundaries.
If all the methods of the event interface pass automation-compatible types (they are VARIANT-compatible), you can set an attribute of "oleautomation" in the source .idl file. When an ATL server is registered, its type library is also registered. This sets up the marshaler for this interface to be the universal marshaler (in OleAut32.dll).
If the event interface passes non-automation-compatible types, then a proxy DLL needs to be built and registered. The ATL Project Wizard creates a proxy makefile in your project directory with the name <Project>.mk. You can run NMake.exe on this .mk file to build the proxy DLL.