Compartilhar via


Accessing Objects

A version of this page is also available for

Windows Embedded CE 6.0 R3

4/8/2010

To access an object, the service manager needs to pass the object's unique HREPLITEM handle to an IReplStore or IReplObjHandler method. To the service manager, the handle is a 32-bit number created by the desktop provider. To the desktop provider, the handle is a pointer to an internal structure or class instance.

Using the time stamp or version number in the HREPLITEM, the desktop provider can determine whether two handles represent the same object, as well as which of the two handles represents the more-recent version. IReplStore::CompareItem compare the object identifiers contained in the two handles. The following table shows the possible return values for this method.

Value Condition

1

The first object identifier is greater than the second object identifier.

0

The first object identifier is equal to the second object identifier.

–1

The first object identifier is less than the second object identifier.

Because the object identifiers are stored in an ascending-identifier sequence, the service manager can perform an efficient binary search, rather than checking every entry in the table. In the case where both items have changed, you should provide a secondary method of comparing them to determine which one should be kept.

The following code example shows how to implement IReplStore::CompareItem.

Note

To make the following code example easier to read, error checking is not included. This code example should not be used in a release configuration unless it has been modified to include secure error handling.

STDMETHODIMP_(int) CMySyncClass::CompareItem
   (
      HREPLITEM hItem1,
      HREPLITEM hItem2
   )
   {
      CItem* pObj1 = (CItem*)hItem1;
      CItem* pObj2 = (CItem*)hItem2;

      if( pObj1->IsConflictObject() )
      {
         if( !pObj2->IsConflictObject() )
            return 1;

         // Both are conflict objects, so use some other property
         // to compare the.objets
         if( pObj1->SecondaryCompareFunc > pObj2->SecondaryCompareFunc ) return 1;
         if( pObj1->SecondaryCompareFunc < pObj2->SecondaryCompareFunc ) return -1;
         return 0;
      }
      else if( pObj2->IsConflictObject() )
         return -1;

      // Neither are conflict objects, so compare as usual
      if (pItem1->m_uid == pItem2->m_uid)
         return  0;
      if (pItem1->m_uid <  pItem2->m_uid)
         return -1;
      return 1;
   }

CFolder and CItem are COM classes based on CReplObject. The following code example shows the definition of these classes.

#define OT_ITEM    1
#define OT_FOLDER  2

class CReplObject
{
public:
   virtual ~CReplObject() {}
   UINT     m_uType;
};

class CFolder: public CReplObject
{
public:
   CFolder (void) { m_uType = OT_FOLDER; }
   virtual ~CFolder() {}
};

class CItem: public CReplObject
{
public:
   CItem (void)
   { m_uType = OT_ITEM;
     memset (&m_ftModified, 0, sizeof (m_ftModified));
   }
   BOOL IsConflictObject();
   BOOL SecondaryCompareFunc();
   virtual ~CItem() {}
   UINT     m_uid;
   FILETIME m_ftModified;
};

See Also

Concepts

Developing the Desktop Provider