Microsoft KB Archive/183216

= You may receive an error message when you call the AtlAdvise function to set up a connection point =

Article ID: 183216

Article Last Modified on 6/2/2005

-

APPLIES TO

 Microsoft ActiveX Template Library 3.0, when used with:  Microsoft Visual C++ 4.2 Enterprise Edition

 Microsoft Visual C++ 5.0 Enterprise Edition

 Microsoft Visual C++ 6.0 Enterprise Edition

 Microsoft Visual C++ 4.2 Professional Edition</li></ul>

 Microsoft Visual C++ 5.0 Professional Edition</li></ul>

 Microsoft Visual C++ 6.0 Professional Edition</li></ul>

 Microsoft Visual C++ 6.0 Standard Edition</li></ul>

 Microsoft Visual C++ .NET 2002 Standard Edition</li></ul>

 Microsoft Visual C++ .NET 2003 Standard Edition</li></ul> </li> Microsoft ActiveX Template Library 2.0, when used with:  Microsoft Visual C++ 4.2 Enterprise Edition</li></ul>

 Microsoft Visual C++ 5.0 Enterprise Edition</li></ul>

 <li>Microsoft Visual C++ 6.0 Enterprise Edition</li></ul>

<ul> <li>Microsoft Visual C++ 4.2 Professional Edition</li></ul>

<ul> <li>Microsoft Visual C++ 5.0 Professional Edition</li></ul>

<ul> <li>Microsoft Visual C++ 6.0 Professional Edition</li></ul>

<ul> <li>Microsoft Visual C++ 6.0 Standard Edition</li></ul>

<ul> <li>Microsoft Visual C++ .NET 2002 Standard Edition</li></ul>

<ul> <li>Microsoft Visual C++ .NET 2003 Standard Edition</li></ul> </li> <li>Microsoft ActiveX Template Library 2.1, when used with: <ul> <li>Microsoft Visual C++ 4.2 Enterprise Edition</li></ul>

<ul> <li>Microsoft Visual C++ 5.0 Enterprise Edition</li></ul>

<ul> <li>Microsoft Visual C++ 6.0 Enterprise Edition</li></ul>

<ul> <li>Microsoft Visual C++ 4.2 Professional Edition</li></ul>

<ul> <li>Microsoft Visual C++ 5.0 Professional Edition</li></ul>

<ul> <li>Microsoft Visual C++ 6.0 Professional Edition</li></ul>

<ul> <li>Microsoft Visual C++ 6.0 Standard Edition</li></ul>

<ul> <li>Microsoft Visual C++ .NET 2002 Standard Edition</li></ul>

<ul> <li>Microsoft Visual C++ .NET 2003 Standard Edition</li></ul> </li></ul>

-

<div class="notice_section">

This article was previously published under Q183216

<div class="symptoms_section">

SYMPTOMS
Calling the AtlAdvise function to setup a connection point might return one of the following error numbers:

0x80004002 (E_NOINTERFACE or "No such interface supported")

0x80040200 (CONNECT_E_NOCONNECTION)

0x80040202 (CONNECT_E_CANNOTCONNECT)

<div class="cause_section">

E_NOINTERFACE Error
The E_NOINTERFACE error is returned when AtlAdvise calls the QueryInterface method for IID_IConnectionPointContainer and fails.

CONNECT_E_NOCONNECTION Error
The CONNECT_E_NOCONNECTION error is returned when AtlAdvise calls the IConnectionPointContainer::FindConnectionPoint method and fails. The ATL implementation of the IConnectionPointContainerImpl::FindConnectionPoint function looks in the connection point map for the event interface and returns this error if it doesn't find it.

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.

<div class="resolution_section">

E_NOINTERFACE Error
For the E_NOINTERFACE error, verify that the source or server supports the IconnectionPointContainer interface. In ATL, this means that the source object should derive from the IConnectionPointContainerImpl class and that IConnectionPointContainer needs to be in the COM map, as in the following example:

Sample Code
class ATL_NO_VTABLE CMySource : public IConnectionPointContainerImpl<CMySource> ...

BEGIN_COM_MAP(CMySource) ... COM_INTERFACE_ENTRY_IMPL(IConnectionPointContainer) END_COM_MAP

CONNECT_E_NOCONNECTION Error
For the CONNECT_E_NOCONNECTION error, verify that there is a connection point entry for the globally unique identifier (GUID) of the event interface in the connection point map, as in the following example:

Sample Code
BEGIN_CONNECTION_POINT_MAP(CMySource) CONNECTION_POINT_ENTRY(DIID__MySourceEvents) END_CONNECTION_POINT_MAP

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.

<div class="moreinformation_section">

MORE INFORMATION
If you look up these HRESULTs in the Error Lookup tool, you get a different description. 0x80040200 appears as "Unable to impersonate DCOM client" or CO_E_FAILEDTOIMPERSONATE. 0x80040202 appears as "Unable to open the access token of the current thread" or CO_E_FAILEDTOOPENTHREADTOKEN. These HRESULTS have a Facility of FACILITY_ITF, which means they are used for custom interfaces and there can be duplicates (the Facility is bits 15-30 of the HRESULT).

AtlAdvise wraps the following steps:
 * 1) Calls QueryInterface to get an IConnectionPointContainer*.
 * 2) Calls IConnectionPointContainer::FindConnectionPoint to get an IConnectionPoint*.
 * 3) Calls IConnectionPoint::Advise.

<div class="references_section">