⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 377-381.html

📁 WindowsCE.[Essential Windows CE Application Programming].Jon Wiley & Son.zip
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<FONT FACE="Arial,Helvetica" SIZE="-1">
To access the contents, click the chapter and section titles.
</FONT>
<P>
<B>Essential Windows CE Application Programming</B>
<FONT SIZE="-1">
<BR>
<I>(Publisher: John Wiley & Sons, Inc.)</I>
<BR>
Author(s): Robert Burdick
<BR>
ISBN: 0471327476
<BR>
Publication Date: 03/01/99
</FONT>
<P>
<form name="Search" method="GET" action="http://search.earthweb.com/search97/search_redir.cgi">

<INPUT TYPE="hidden" NAME="Action" VALUE="Search">
<INPUT TYPE="hidden" NAME="SearchPage" VALUE="http://search.earthweb.com/search97/samples/forms/srchdemo.htm">
<INPUT TYPE="hidden" NAME="Collection" VALUE="ITK">
<INPUT TYPE="hidden" NAME="ResultTemplate" VALUE="itk-simple-intrabook.hts">
<INPUT TYPE="hidden" NAME="ViewTemplate" VALUE="view.hts">

<font face="arial, helvetica" size=2><b>Search this book:</b></font><br>
<INPUT NAME="queryText" size=50 VALUE="">&nbsp;<input type="submit" name="submitbutton" value="Go!">
<INPUT type=hidden NAME="section_on" VALUE="on">
<INPUT type=hidden NAME="section" VALUE="http://www.itknowledge.com/reference/standard/0471327476/">

</form>


<!-- Empty Reference Subhead -->

<!--ISBN=0471327476//-->
<!--TITLE=Essential Windows CE Application Programming//-->
<!--AUTHOR=Robert Burdick//-->
<!--PUBLISHER=John Wiley & Sons, Inc.//-->
<!--IMPRINT=Wiley Computer Publishing//-->
<!--CHAPTER=14//-->
<!--PAGES=377-381//-->
<!--UNASSIGNED1//-->
<!--UNASSIGNED2//-->

<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="375-377.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="381-385.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
<H3><A NAME="Heading8"></A><FONT COLOR="#000077">Reconstructing Folders and Items</FONT></H3>
<P>After a connection between a Windows CE device and a desktop computer has been established and any ActiveSync service providers registered on the desktop computer have been initialized, the most recently synchronized data is reconstructed.
</P>
<P>The service manager reconstructs this data snapshot by asking the desktop service provider to reassemble all data folders and their item contents from the data stored by the manager in REPL.DAT. The IReplStore method that the manager calls to accomplish this is called <I>BytesToObject</I>:</P>
<!-- CODE SNIP //-->
<PRE>
  HREPLOBJ BytesToObject(lpb, cb);
</PRE>
<!-- END CODE SNIP //-->
<P><I>lpb</I> is a pointer to a BYTE array and <I>cb</I> is a UINT indicating the number of bytes in the <I>lpb</I> buffer. <I>lpb</I> contains data item information from REPL.DAT.</P>
<P>The service manager gets the bytes that it writes to REPL.DAT for a particular item by calling the IReplStore method <I>ObjectToBytes</I>.</P>
<!-- CODE SNIP //-->
<PRE>
  UINT ObjectToBytes(hObject, lpb);
</PRE>
<!-- END CODE SNIP //-->
<P><I>hObject</I> is an HREPLITEM or HREPLFLD handle, and <I>lpb</I> is a pointer to the BYTE buffer in which the service provider should store the pertinent information. This method returns the number of bytes placed in the <I>lpb</I> byte array.</P>
<P>The phone list application desktop service provider implements <I>ObjectToBytes</I> as shown in the following code. From this code we can see that the service manager saves the object type (folder or item) and a synchronization option for folders. It saves the object type, object identifier, and last modified time in the case of an item, i.e., a phone entry.</P>
<!-- CODE //-->
<PRE>
  STDMETHODIMP_(UINT) CStore::ObjectToBytes(
    HREPLOBJ hObject,
    LPBYTE  lpb)
  &#123;
    LPBYTE  lpbStart = lpb;
    CReplObject *pObject = (CReplObject *)hObject;
    CFolder  *pFolder = (CFolder *)pObject;
    CItem   *pItem = (CItem *)pObject;
    if (lpbStart)
    &#123;
    *(PUINT)lpb = pObject-&gt;m_uType;
    &#125;
    lpb &#43;= sizeof( pObject-&gt;m_uType);
    switch(pObject-&gt;m_uType)
    &#123;
    case OT_FOLDER:
    if (lpbStart)
    &#123;
     *(PUINT)lpb = pFolder-&gt;m_uSyncOpt;
    &#125;
    lpb &#43;= sizeof(pFolder-&gt;m_uSyncOpt);
    break;
    case OT_ITEM:
    if (lpbStart)
    &#123;
     *(PUINT)lpb = pItem-&gt;m_uid;
    &#125;
    lpb &#43;= sizeof(pItem-&gt;m_uid);
    if (lpbStart)
    &#123;
     *(FILETIME *)lpb = pItem-&gt;m_ftModified;
    &#125;
    lpb &#43;= sizeof(pItem-&gt;m_ftModified);
    break;
    &#125;
    return (lpb-lpbStart);
  &#125;
</PRE>
<!-- END CODE //-->
<P>The service manager passes in the folder or item as an HREPLOBJ handle. <I>ObjectToBytes</I> first casts this handle to both a CItem pointer and a CFolder pointer. The function then writes the object type to the byte array pointed to by <I>lpb</I>, and then moves the pointer to the next free byte.</P>
<P>Next, depending on whether the object passed in is a folder or an item, the other pertinent object data is added to the byte array to be written out by the service manager.</P>
<P>It might seem strange that the service manager asks the service provider to fill the byte array that is written to REPL.DAT. After all, the service manager passed in a valid item or folder handle containing all of the item data. Why didn&#146;t the manager write the data itself?</P>
<P>The answer goes back to the original idea that the ActiveSync service manager only facilitates the entire synchronization process. The data stored in REPL.DAT is used to discover changes in the data store between synchronizations. But as we will see, the comparisons needed to detect data changes are done by the service provider at the request of the service manager.</P>
<P>Therefore, the service manager lets the service provider tell which specific pieces of information about a folder or item should be stored. Hence the calls to <I>ObjectToBytes</I>.</P>
<P><I>BytesToObject</I> works in a similar way. Whenever synchronized data needs to be reconstructed, the service manager passes the entire set of data stored with a particular object to the service provider. The provider then extracts those pieces of information it will need for other synchronization tasks.</P>
<P>For example, the phone list application implements <I>BytesToObject</I> as follows:</P>
<!-- CODE //-->
<PRE>
  STDMETHODIMP_(HREPLOBJ) CStore::BytesToObject(
    LPBYTE lpb,
    UINT cb)
  &#123;
    CReplObject *pObject = NULL;
    CFolder  *pFolder;
    CItem   *pItem;
    UINT  uType = *(PUINT)lpb;
    lpb &#43;= sizeof(uType);
    switch(uType)
    &#123;
    case OT_FOLDER:
    pObject = pFolder = new CFolder;
    pFolder-&gt;m_uSyncOpt = *(PUINT)lpb;
    lpb &#43;= sizeof(pFolder-&gt;m_uSyncOpt);
    break;
    case OT_ITEM:
    pObject = pItem = new CItem;
    pItem-&gt;m_uid = *(PUINT)lpb;
    lpb &#43;= sizeof(pItem-&gt;m_uid);
    pItem-&gt;m_ftModified = *(FILETIME *)lpb;
    lpb &#43;= sizeof(pItem-&gt;m_ftModified);
    break;
    &#125;
    return (HREPLOBJ)pObject;
  &#125;
</PRE>
<!-- END CODE //-->
<P>The service manager passes a byte array of length <I>cb</I>. The service provider proceeds by extracting the parts of that array it is interested in as defined by the CItem and CFolder data members. Once it has finished, the provider returns a handle to the new object. As we will see in the next section, the service manager uses these handles during object enumeration.</P><P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="375-377.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="381-385.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>


<!-- all of the reference materials (books) have the footer and subfoot reveresed -->
<!-- reference_subfoot = footer -->
<!-- reference_footer = subfoot -->

<!-- BEGIN SUB FOOTER -->
		<br><br>
		</TD>
    </TR>
	</TABLE>

		
	<table width="640" border=0 cellpadding=0 cellspacing=0>
		<tr>
		<td align="left" width=135><img src="/images/white.gif" width=100 height="1" alt="" border="0"></td>
		
		
<!-- END SUB FOOTER -->

<!-- all of the books have the footer and subfoot reveresed -->
<!-- reference_subfoot = footer -->
<!-- reference_footer = subfoot -->

<!-- FOOTER -->
			
		<td width="515" align="left" bgcolor="#FFFFFF">
<font face="arial, helvetica" size="1"><b><a href="/products.html"><font color="#006666">Products</font></a>&nbsp;|&nbsp; <a href="/contactus.html"><font color="#006666">Contact Us</font></a>&nbsp;|&nbsp; <a href="/aboutus.html"><font color="#006666">About Us</font></a>&nbsp;|&nbsp; <a href="http://www.earthweb.com/corporate/privacy.html" target="_blank"><font color="#006666">Privacy</font></a> &nbsp;|&nbsp; <a href="http://www.itmarketer.com/" target="_blank"><font color="#006666">Ad Info</font></a> &nbsp;|&nbsp; <a href="/"><font color="#006666">Home</font></a></b>
		<br><br>
		
		Use of this site is subject to certain <a href="/agreement.html">Terms &amp; Conditions</a>, <a href="/copyright.html">Copyright &copy; 1996-1999 EarthWeb Inc.</a><br> 
All rights reserved.  Reproduction whole or in part in any form or medium without express written permision of EarthWeb is prohibited.</font><p>
</td>
		</tr>
</table>
</BODY>
</HTML>

<!-- END FOOTER -->

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -