Timestamper Class Extension
TimestampedOCDescription.cpp
// Copyright 2006 ESRI
// 
// All rights reserved under the copyright laws of the United States
// and applicable international laws, treaties, and conventions.
// 
// You may freely redistribute and use this sample code, with or
// without modification, provided you include the original copyright
// notice and use restrictions.
// 
// See the use restrictions.

// TimestampedOCDescription.cpp : Implementation of CTimestampedOCDescription
#include "stdafx.h"
#include "Timestamper.h"
#include "TimestamperUtils.h"
#include "TimestampedOCDescription.h"

/////////////////////////////////////////////////////////////////////////////
// CTimestampedOCDescription

// IObjectClassDescription
STDMETHODIMP CTimestampedOCDescription::get_Name(BSTR *Name)
{
  if (!Name) return E_POINTER;

  CComBSTR str(L"Timestamped Object Class");
  *Name = str.Detach();
  return S_OK; 
}

STDMETHODIMP CTimestampedOCDescription::get_AliasName(BSTR *Name)
{
  if (!Name) return E_POINTER;

  CComBSTR str(L"");
  *Name = str.Detach();
  return S_OK; 
}

STDMETHODIMP CTimestampedOCDescription::get_ModelName(BSTR *Name)
{
  if (!Name) return E_POINTER;

  CComBSTR str(L"");
  *Name = str.Detach();
  return S_OK; 
}

STDMETHODIMP CTimestampedOCDescription::get_ModelNameUnique(VARIANT_BOOL *IsUnique)
{
  if (!IsUnique) return E_POINTER;

  *IsUnique = VARIANT_FALSE;
  return S_OK;
}

STDMETHODIMP CTimestampedOCDescription::get_InstanceCLSID(IUID **InstanceCLSID)
{

  if (!InstanceCLSID) return E_POINTER;

  HRESULT hr;

  IUIDPtr ipClsid(CLSID_UID);

  OLECHAR str[101];
  StringFromGUID2(CLSID_Object, str, 100);
  
  hr = ipClsid->put_Value(CComVariant(str));
  if (FAILED(hr)) return hr;

  *InstanceCLSID = ipClsid.Detach(); // pass ownership of object to client

  return S_OK;
}

STDMETHODIMP CTimestampedOCDescription::get_ClassExtensionCLSID(IUID **ClassExtensionCLSID)
{
  if (!ClassExtensionCLSID) return E_POINTER;

  HRESULT hr;

  IUIDPtr ipClsid(CLSID_UID);

  OLECHAR str[101];
  StringFromGUID2(CLSID_TimestampClassExtension, str, 100);
  
  hr = ipClsid->put_Value(CComVariant(str));
  if (FAILED(hr)) return hr;

  *ClassExtensionCLSID = ipClsid.Detach(); // pass ownership of object to client

  return S_OK;
}

STDMETHODIMP CTimestampedOCDescription::get_RequiredFields(IFields **fieldDescription)
{
  if (!fieldDescription) return E_POINTER;

  HRESULT hr;
  
  // First get the standard fields for an object class
  IObjectClassDescriptionPtr ipOCDesc(CLSID_ObjectClassDescription);

  IFieldsPtr ipFields;
  hr = ipOCDesc->get_RequiredFields(&ipFields);
  if (FAILED(hr)) return hr;

  IFieldsEditPtr ipFieldsEdit(ipFields);

  // Now add the extra fields
  hr = AddTimestampFields(ipFieldsEdit);
  if (FAILED(hr)) return hr;

  *fieldDescription = ipFieldsEdit.Detach(); // pass ownership of object to client 
  return S_OK;
}