The host saves its version of the dynamic type information and uses a cookie to determine whether that type information needs to be updated. (The cookie is a parameter to the GetDynamicTypeInfo method.) The designer should save the cookie value, incrementing it only if an unrecoverable error occurs when the persistent data are loaded.
You can easily save the cookie value in the property map of the derived class as follows:
class CShapesDynInstCtl
{
…
BEGIN_PROP_MAP(CShapesDynDsgnCtl)
PROP_DATA_ENTRY("IProvideDynamicClassInfoImpl::m_dwDynamicTICookie", m_dwDynamicTICookie, VT_UINT)
END_PROP_MAP()
…
}
If the persistent data fail to load correctly, your designer must increment the cookie. The following example shows how to override the IPersistStreamInitImpl::IPersistStreamInit_Load method in the derived class and increment the cookie:
HRESULT CShapesDynInstCtl::IPersistStreamInit_Load(LPSTREAM pStream, ATL_PROPMAP_ENTRY * pMap
{
HRESULT hr = E_FAIL;
if(!pStream)
CLEANUP_ON_FAILURE(E_INVALIDARG);
hr = AtlIPersistStreamInit_Load(pStream,pMap,this,GetUnknown());
CleanUp:
if(FAILED(hr))
++m_dwDynamicTICookie;
}