Microsoft KB Archive/192093

= PRB: Compiler Errors When Porting IObjectSafetyImpl To ATL 3.0 =

Article ID: 192093

Article Last Modified on 12/10/2003

-

APPLIES TO

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

 Microsoft Visual C++ 6.0 Professional Edition

 Microsoft Visual C++ 6.0 Standard Edition 

-

<div class="notice_section">

This article was previously published under Q192093

<div class="symptoms_section">

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:

<pre class="fixed_text">  error C2976: 'IObjectSafetyImpl' : too few template arguments

<pre class="fixed_text">  error C2504: 'IObjectSafetyImpl<class CMyObject>' : base class undefined

<pre class="fixed_text">  error C2440: 'static_cast' : cannot convert from 'class CMyObject *' to

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

<pre class="fixed_text">  error C2065: 'm_dwSafety' : undeclared identifier

<div class="cause_section">

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.

<div class="resolution_section">

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

<ol>  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 > </li> In the COM map, change COM_INTERFACE_ENTRY_IMPL(IObjectSafety) to COM_INTERFACE_ENTRY(IObjectSafety).</li> 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.</li></ol>

<div class="status_section">

STATUS
This behavior is by design.

<div class="references_section">