You receive the "C4199" compiler error together with the "ATL4058" warning when you build attributed ATL code in Visual C++ .NET (315002)



The information in this article applies to:

  • Microsoft Visual C++ .NET (2002)
  • Microsoft Visual C++ .NET (2003)

This article was previously published under Q315002

SYMPTOMS

C4199 is an undocumented compiler warning. However, you may receive this warning in conjunction with an ATL4058 warning when you build attributed Active Template Library (ATL) code. For example, you could get the following message when you build the project:
warning C4199: coclass
Atl Attribute Provider : warning ATL4058: "ISomeInterface" is not an interface defined in embedded IDL. It will not be replaced with the corresponding IDispatchImpl.
NOTE: Visual C++ .NET supports both the managed code model that is provided by the .NET Framework and the unmanaged native Windows code model. The information in this article applies only to unmanaged Visual C++ code.

CAUSE

This error occurs because you did not define ISomeInterface in embedded interface definitions in your code.

RESOLUTION

When an interface that derives from IDispatch is not in embedded Interface Definition Language (IDL) code (or is derived from an interface that is not in embedded IDL code), the attribute provider cannot replace the interface with the corresponding IDispatchImpl, which should be of the form.
IDispatchImpl<ISomeInterface, &__uuidof(ISomeInterface), [LIBID of the type
 library that has type information for the interface], 
[Major version of the type library], [Minor version of the type library]> 
				
The ATL attribute provider cannot determine the type information from the header file that defines the interface.

The resolution that you select depends on what you want to accomplish:
  • If your interface is a dispinterface or a dual interface and you are implementing the IDispatch methods, you can ignore the error message.
  • If your interface is a dispinterface or dual interface and you expect the attribute provider to implement the IDispatch methods (either through the use of an IDispatchImpl or the compiler to generate the IDispatch methods), the warning is letting you know that the attribute provider cannot implement the IDispatch methods for you. To fix this, derive your class from IDIspatchImpl instead of the interface.

STATUS

This behavior is by design.

MORE INFORMATION

Steps to Reproduce the Behavior

  1. Create an ATL project. Use the default options.
  2. Add a C++ header file called Test.h that includes the following code to the project:
    // Test.h : Declaration of the CTest
    #include <mshtml.h>
    [ coclass ]
    class CTest: public IHTMLFiltersCollection
    {
    public :
        virtual HRESULT STDMETHODCALLTYPE get_length(long *p)
        {
           return E_NOTIMPL;
        }
        virtual HRESULT STDMETHODCALLTYPE get__newEnum(IUnknown **p)
        {
           return E_NOTIMPL;
        }
        
        virtual HRESULT STDMETHODCALLTYPE item(VARIANT *pvarIndex, VARIANT *pvarResult)
        {
           return E_NOTIMPL;
        }
    };
    					
  3. Add a C++ file named Test.cpp to the project that includes the following code:
    // Test.cpp : Implementation of CTest
    
    #include "stdafx.h"
    #include "Test.h"
    					
  4. On the Project menu, click Properties. Click the C/C++ tab. Under the General category, change the warning level to Level 4(/W4). Apply the changes.
  5. Build your project.

REFERENCES

For more information, visit the following Microsoft Developer Network (MSDN) Web sites:

Modification Type:MajorLast Reviewed:6/27/2006
Keywords:kbCompiler kbprb kbProd2Web KB315002 kbAudDeveloper