PRB: Compiler Errors When Porting IObjectSafetyImpl To ATL 3.0 (192093)



The information in this article applies to:

  • The Microsoft Active Template Library (ATL) 3.0, when used with:
    • Microsoft Visual C++, 32-bit Enterprise Edition 6.0
    • Microsoft Visual C++, 32-bit Professional Edition 6.0
    • Microsoft Visual C++, 32-bit Learning Edition 6.0

This article was previously published under Q192093

SYMPTOMS

When you port a Component Object Model (COM) object that uses IObjectSafetyImpl from ATL 2.1 to ATL 3.0, you might encounter the following compilation errors:

   error C2976: 'IObjectSafetyImpl' : too few template arguments
				


   error C2504: 'IObjectSafetyImpl<class CMyObject>' : base class undefined
				


   error C2440: 'static_cast' : cannot convert from 'class CMyObject *' to
				

'class ATL::IObjectSafetyImpl<class CMyObject> *'



   error C2065: 'm_dwSafety' : undeclared identifier
				

CAUSE

IObjectSafetyImpl was changed in ATL 3.0. In ATL 2.1, the IObjectSafetyImpl class marked the control as supporting the "safe for scripting" option by default. For security reasons, this default has been removed in ATL 3.0. You must now explicitly specify your safety options using the second template parameters.

The ATL 3.0 implementation also allows you to support the "safe for initialization" setting using the second template argument.

RESOLUTION

You must perform three tasks to correctly implement IObjectSafetyImpl in ATL 3.0:

  1. In ATL 3.0 IObjectSafetyImpl<> takes a second template argument that specifies the supported safety option. This can be a combination of INTERFACESAFE_FOR_UNTRUSTED_CALLER (safe for scripting) and INTERFACESAFE_FOR_UNTRUSTED_DATA (safe for intialization). For example:
          // Indicates the object supports the "safe for scripting" and "safe
          // for initialization" settings.
          IObjectSafetyImpl<CMyObject, INTERFACESAFE_FOR_UNTRUSTED_CALLER
             |INTERFACESAFE_FOR_UNTRUSTED_DATA >
    						
  2. In the COM map, change COM_INTERFACE_ENTRY_IMPL(IObjectSafety) to COM_INTERFACE_ENTRY(IObjectSafety).
  3. In ATL 2.1, the IObjectSafetyImpl::m_dwSafety member indicated which safety options were enabled. In ATL 3.0, this member has been renamed to m_dwCurrentSafety. So any reference to m_dwSafety must be changed to m_dwCurrentSafety.

STATUS

This behavior is by design.

REFERENCES

ARTICLE-ID: 168371
   TITLE     : HOWTO: IObjectSafety Marks ATL Controls Safe for
				

Initializing



(c) Microsoft Corporation 1998, All Rights Reserved. Contributions by Jaganathan Thangavelu, Microsoft Corporation.

Modification Type:MajorLast Reviewed:12/10/2003
Keywords:kbprb KB192093